It seems there are still authors unaware that the use of UIFrameFlash/Fade functions are a source of taint, and it has been so for quite literally, years. These functions were never actually intended to be used by addons as can be seen by the way they are implemented.
This is a short guide to implementing the same behaviour using the animation system.
The following example assumes "myFrame" is the frame you want to flash. First, create an animation group (container) attached to your frame:
local flasher = myFrame:CreateAnimationGroup()
Now you need to create the animations. In this example, I flash my frame in and out. Each fade in/out lasts 0.5 seconds, totalling 1 second. My frame is currently shown but has an Alpha value of 0.
local fade1 = flasher:CreateAnimation("Alpha")
fade1:SetDuration(0.5)
fade1:SetChange(1)
fade1:SetOrder(1)
local fade2 = flasher:CreateAnimation("Alpha")
fade2:SetDuration(0.5)
fade2:SetChange(-1)
fade2:SetOrder(2)
The :SetChange call dictates the "direction" you want to fade your frame. In this case, I used "1" to make the frame fully visible, then "-1" to make the frame transparent again.
Now, to execute this flash all I need to call is :Play on the animation group I created.
flasher:Play()
That's a simple example of fading a transparent frame in and out, it will return to being transparent once the animation is finished. But what if you want it to be visible after the animation has completed? Here's how to implement the "showWhenDone" functionality.
The OnFinished script runs when your animation finishes, and in this case, makes your frame "show when done".
Now to cover the final args, "holding" time. The animation system has an in-built delay system (:SetStartDelay, :SetEndDelay). In this case, end delay can be used to achieve both "flashOutHoldTime" and "flashInHoldTime". In the following example I've added a hold in and hold out time, lasting 1 second each, using end delays:
-- Flashing in
local fade1 = flasher:CreateAnimation("Alpha")
fade1:SetDuration(0.5)
fade1:SetChange(1)
fade1:SetOrder(1)
-- Holding it visible for 1 second
fade1:SetEndDelay(1)
-- Flashing out
local fade2 = flasher:CreateAnimation("Alpha")
fade2:SetDuration(0.5)
fade2:SetChange(-1)
fade2:SetOrder(3)
-- Holding it for 1 second before calling OnFinished
fade2:SetEndDelay(1)
Now my frame will fade in over 0.5 seconds, will sit there for 1 second, will fade out over 0.5 seconds, will sit there faded out for 1 second. After that is done, it will call OnFinished.
Thanks for this, it makes it very easy to implement.
Quick question : wowpedia doesn't list the script handlers for animation. Anyone can point me where I can get the list? In particular, I'm looking for a "before starting the anim" handler.
[Edit: found it, it's OnPlay. I guess I'll go update the Widget handlers page now.]
Is there a guide or organized list somewhere of "best practices" for avoiding common sources of taint in addon dev? (ie what *else* are addons commonly doing wrong)
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
This is a short guide to implementing the same behaviour using the animation system.
Replacing UIFrameFlash:
The following example assumes "myFrame" is the frame you want to flash. First, create an animation group (container) attached to your frame:
Now you need to create the animations. In this example, I flash my frame in and out. Each fade in/out lasts 0.5 seconds, totalling 1 second. My frame is currently shown but has an Alpha value of 0.
The :SetChange call dictates the "direction" you want to fade your frame. In this case, I used "1" to make the frame fully visible, then "-1" to make the frame transparent again.
Now, to execute this flash all I need to call is :Play on the animation group I created.
That's a simple example of fading a transparent frame in and out, it will return to being transparent once the animation is finished. But what if you want it to be visible after the animation has completed? Here's how to implement the "showWhenDone" functionality.
The OnFinished script runs when your animation finishes, and in this case, makes your frame "show when done".
Now to cover the final args, "holding" time. The animation system has an in-built delay system (:SetStartDelay, :SetEndDelay). In this case, end delay can be used to achieve both "flashOutHoldTime" and "flashInHoldTime". In the following example I've added a hold in and hold out time, lasting 1 second each, using end delays:
Now my frame will fade in over 0.5 seconds, will sit there for 1 second, will fade out over 0.5 seconds, will sit there faded out for 1 second. After that is done, it will call OnFinished.
Quick question : wowpedia doesn't list the script handlers for animation. Anyone can point me where I can get the list? In particular, I'm looking for a "before starting the anim" handler.
[Edit: found it, it's OnPlay. I guess I'll go update the Widget handlers page now.]
Is there a guide or organized list somewhere of "best practices" for avoiding common sources of taint in addon dev? (ie what *else* are addons commonly doing wrong)