Mitcho_0
%Europe/Berlin %263 %2009, 07:19
Ik ben een class aan het schrijven die een Sprite extend.
Ik wil dat een scripted animatie wordt gestart, wanneer een instance van deze class op de stage wordt gezet.
En zodra de animatie is afgelopen, moet ie van de stage af.
Dat gaat goed, totdat ik meerdere instances op de stage zet met een kleine interval ertussen.
Zodra de 1ste afgelopen is, verdwijnt ie. Maar de 2e stopt ook, terwijl hij nog midden in de animatie zit.
Het lijkt dus alsof ze allemaal dezelfde AnimatorBase gebruiken.
Hier beneden staat mijn class.
Eerst waren de AnimatorFactory en Motion static vars, maar die heb ik nu gewoon private gemaakt... dat maakt geen verschil.
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.text.TextFieldAutoSize;
import flash.events.Event;
import fl.motion.AnimatorFactory;
import fl.motion.Motion;
import fl.motion.AnimatorBase;
import fl.motion.MotionEvent;
public class PointsText extends MovieClip
{
public static const green:uint = 0x00CC00;
public static const red:uint = 0xCC0000;
public static const orange:uint = 0xCCA400;
public static const format:TextFormat = new TextFormat("Arial",32,orange,false,false,false,null,null,TextFormatA lign.CENTER);;
private var $mo:Motion = null;
private var $af:AnimatorFactory;
public function getAnimator(object:DisplayObject):AnimatorBase
{
if($mo == null) {
$mo = new Motion();
$mo.duration = 25;
$mo.addPropertyArray("y", [0,-11.2361,-21.9958,-32.2793,-42.0807,-51.4058,-60.2547,-68.6215,-76.512,-83.9261,-90.8583,-97.3142,-103.294,-108.791,-113.812,-118.357,-122.42,-126.007,-129.117,-131.745,-133.897,-135.573,-136.767,-137.484,-137.725]);
$mo.addPropertyArray("scaleX", [1.000000,1.081583,1.159708,1.234375,1.305542,1.373 250,1.437500,1.498250,1.555541,1.609375,1.659708,1 .706583,1.750000,1.789917,1.826375,1.859375,1.8888 75,1.914917,1.937500,1.956583,1.972208,1.984375,1. 993042,1.998250,2.000000]);
$mo.addPropertyArray("scaleY", [1.000000,1.081583,1.159708,1.234375,1.305542,1.373 250,1.437500,1.498250,1.555541,1.609375,1.659708,1 .706583,1.750000,1.789917,1.826375,1.859375,1.8888 75,1.914917,1.937500,1.956583,1.972208,1.984375,1. 993042,1.998250,2.000000]);
$mo.addPropertyArray("blendMode", ["normal"]);
$mo.addPropertyArray("alphaMultiplier", [1,0.96,0.92,0.88,0.84,0.8,0.76,0.72,0.68,0.64,0.6, 0.56,0.52,0.48,0.44,0.4,0.36,0.32,0.28,0.24,0.2,0. 16,0.12,0.06,0.04]);
$af = new AnimatorFactory($mo);
}
return $af.addTarget(object, 1, true);
}
private var $animator:AnimatorBase;
private var $textfield:TextField;
public function PointsText(points:int):void
{
$textfield = getTextField();
$textfield.name = "textfield";
addChild($textfield);
if(points>0)
{
$textfield.textColor = green;
$textfield.text = "+" + String(points);
}
else if(points<0)
{
$textfield.textColor = red;
$textfield.text = String(points);
}
addEventListener(Event.ADDED_TO_STAGE, added);
}
private function added(event:Event):void
{
$animator = getAnimator($textfield);
x = stage.mouseX, y = stage.mouseY;
$animator.addEventListener(MotionEvent.MOTION_END, motionEnd);
//$animator.play();
removeEventListener(Event.ADDED_TO_STAGE, added);
addEventListener(Event.REMOVED_FROM_STAGE, removed);
}
private function removed(event:Event):void
{
addEventListener(Event.ADDED_TO_STAGE, added);
}
private function getTextField():TextField
{
var result:TextField = new TextField();
result.defaultTextFormat = format;
result.autoSize = TextFieldAutoSize.CENTER;
result.selectable = false;
result.mouseEnabled = false;
return result;
}
private function motionEnd(event:MotionEvent):void
{
if(parent)
{
parent.removeChild(this);
}
$animator.removeEventListener(MotionEvent.MOTION_E ND, motionEnd);
}
public function get animator():AnimatorBase
{
return $animator;
}
public function get textfield():TextField
{
return $textfield;
}
}
}
Ik wil dat een scripted animatie wordt gestart, wanneer een instance van deze class op de stage wordt gezet.
En zodra de animatie is afgelopen, moet ie van de stage af.
Dat gaat goed, totdat ik meerdere instances op de stage zet met een kleine interval ertussen.
Zodra de 1ste afgelopen is, verdwijnt ie. Maar de 2e stopt ook, terwijl hij nog midden in de animatie zit.
Het lijkt dus alsof ze allemaal dezelfde AnimatorBase gebruiken.
Hier beneden staat mijn class.
Eerst waren de AnimatorFactory en Motion static vars, maar die heb ik nu gewoon private gemaakt... dat maakt geen verschil.
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.text.TextFieldAutoSize;
import flash.events.Event;
import fl.motion.AnimatorFactory;
import fl.motion.Motion;
import fl.motion.AnimatorBase;
import fl.motion.MotionEvent;
public class PointsText extends MovieClip
{
public static const green:uint = 0x00CC00;
public static const red:uint = 0xCC0000;
public static const orange:uint = 0xCCA400;
public static const format:TextFormat = new TextFormat("Arial",32,orange,false,false,false,null,null,TextFormatA lign.CENTER);;
private var $mo:Motion = null;
private var $af:AnimatorFactory;
public function getAnimator(object:DisplayObject):AnimatorBase
{
if($mo == null) {
$mo = new Motion();
$mo.duration = 25;
$mo.addPropertyArray("y", [0,-11.2361,-21.9958,-32.2793,-42.0807,-51.4058,-60.2547,-68.6215,-76.512,-83.9261,-90.8583,-97.3142,-103.294,-108.791,-113.812,-118.357,-122.42,-126.007,-129.117,-131.745,-133.897,-135.573,-136.767,-137.484,-137.725]);
$mo.addPropertyArray("scaleX", [1.000000,1.081583,1.159708,1.234375,1.305542,1.373 250,1.437500,1.498250,1.555541,1.609375,1.659708,1 .706583,1.750000,1.789917,1.826375,1.859375,1.8888 75,1.914917,1.937500,1.956583,1.972208,1.984375,1. 993042,1.998250,2.000000]);
$mo.addPropertyArray("scaleY", [1.000000,1.081583,1.159708,1.234375,1.305542,1.373 250,1.437500,1.498250,1.555541,1.609375,1.659708,1 .706583,1.750000,1.789917,1.826375,1.859375,1.8888 75,1.914917,1.937500,1.956583,1.972208,1.984375,1. 993042,1.998250,2.000000]);
$mo.addPropertyArray("blendMode", ["normal"]);
$mo.addPropertyArray("alphaMultiplier", [1,0.96,0.92,0.88,0.84,0.8,0.76,0.72,0.68,0.64,0.6, 0.56,0.52,0.48,0.44,0.4,0.36,0.32,0.28,0.24,0.2,0. 16,0.12,0.06,0.04]);
$af = new AnimatorFactory($mo);
}
return $af.addTarget(object, 1, true);
}
private var $animator:AnimatorBase;
private var $textfield:TextField;
public function PointsText(points:int):void
{
$textfield = getTextField();
$textfield.name = "textfield";
addChild($textfield);
if(points>0)
{
$textfield.textColor = green;
$textfield.text = "+" + String(points);
}
else if(points<0)
{
$textfield.textColor = red;
$textfield.text = String(points);
}
addEventListener(Event.ADDED_TO_STAGE, added);
}
private function added(event:Event):void
{
$animator = getAnimator($textfield);
x = stage.mouseX, y = stage.mouseY;
$animator.addEventListener(MotionEvent.MOTION_END, motionEnd);
//$animator.play();
removeEventListener(Event.ADDED_TO_STAGE, added);
addEventListener(Event.REMOVED_FROM_STAGE, removed);
}
private function removed(event:Event):void
{
addEventListener(Event.ADDED_TO_STAGE, added);
}
private function getTextField():TextField
{
var result:TextField = new TextField();
result.defaultTextFormat = format;
result.autoSize = TextFieldAutoSize.CENTER;
result.selectable = false;
result.mouseEnabled = false;
return result;
}
private function motionEnd(event:MotionEvent):void
{
if(parent)
{
parent.removeChild(this);
}
$animator.removeEventListener(MotionEvent.MOTION_E ND, motionEnd);
}
public function get animator():AnimatorBase
{
return $animator;
}
public function get textfield():TextField
{
return $textfield;
}
}
}