I have a custom component with a skin attached to it.
There are several different skins for this component, and they are all animated differently. Therefor I've contained the animations with the skinClasses.
When the component is no longer in view, I need to be able to stop the animations so they don't run in the background.
How can I call a stop function on a skin?
My guess was to add two skin states: "animationState" and "idleState".
But the following code does not stop the animation when close()
is called. The skinState does not change.
package {
import spark.components.supportClasses.SkinnableComponent;
[SkinState("animationState")]
[SkinState("idleState")]
public class AnimatedComponent extends SkinnableComponent
{
public function AnimatedComponent
{
setStyle("skinClass", MyAnimatedComponentSkin);
}
public function start():void
{
_isAnimating = true;
invalidateSkinState();
}
public function close():void
{
_isAnimating = false;
invalidateSkinState();
}
private var _isAnimating:Boolean = false;
override protected function getCurrentSkinState():String
{
return _isAnimating ? "animationState" : "idleState";
}
}
}
Here's an example of the way I did it (This doesn't actually answer my question at all, but it worked for what I needed. Hopefully this helps someone else struggling with a similar problem).
I have an Application with a custom skinnable Title and a "STOP" button.
I've created a base class called
MyCustomTitle
which extendsspark.components.supportClasses.SkinnableComponent
, and used a stylesheet "main.css" to apply the skinclass to it.Also, when the app is loaded from the browser, the web-script passes a "theme" parameter to the Application (
this.parameters.theme
). This allows the user to choose the theme, which will determine the skins/animations.Here is the CSS file that defines the skin:
Here is the "red" Skin:
And the "blue" one:
I could have put the animations in the skin classes above. This would work perfectly fine for a non-repeating animation. But because these animations loop, I need to be able to call a
stop()
function on them when they are not being displayed. Since I cannot call functions in the skin, I am instead adding the animation into the hostComponent Class.MyCustomTitle
has a required labelDisplay property for the skins.The animation is defined here, because some of the animation properties are shared between all the different themes. However, as of right now, the animation is null.
This class has an
init()
method to start the animation, and astop()
method.Finally, I can extend
MyCustomTitle
so that it can have a different animation for each theme.Theme "red":
Theme "blue":