PDA

Просмотр полной версии : Copy Motion as ActionScript 3.0 во Flash CS3


NewMan_by
16.05.2007, 16:11
Проблема в следующем.
Если на кадре пишу применение полученого Motion всё отлично работает, вот код:

import fl.motion.Animator;
var motion2:Motion2=new Motion2();
this.addChild(motion2);

var motion2_xml:XML = <Motion duration="30" xmlns="fl.motion.*" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*">
<source>
<Source frameRate="12" x="12.25" y="6.5" scaleX="1" scaleY="1" rotation="0" elementType="movie clip" symbolName="s1">
<dimensions>
<geom:Rectangle left="0" top="0" width="24.5" height="13"/>
</dimensions>
<transformationPoint>
<geom:Point x="0.5" y="0.5"/>
</transformationPoint>
</Source>
</source>

<Keyframe index="0">
<tweens>
<SimpleEase ease="0"/>
</tweens>
</Keyframe>

<Keyframe index="29" x="130"/>
</Motion>;

var motion2_animator:Animator = new Animator(motion2_xml, motion2);
motion2_animator.play();

Если же я делаю Document Class и впишу туда данный код по всем правилам срабатывает как-будто только анимация одного кадра, вот код:

package {
import flash.display.*;
import flash.events.*;
import fl.motion.Animator;
import fl.motion.Motion;
public class Temp extends MovieClip{
public var motion2_xml:XML;
public var motion2:Motion2;
public function Temp(){
trace("Temp");
motion2_xml=<Motion duration="30" xmlns="fl.motion.*" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*">
<source>
<Source frameRate="12" x="12.25" y="6.5" scaleX="1" scaleY="1" rotation="0" elementType="movie clip" symbolName="s1">
<dimensions>
<geom:Rectangle left="0" top="0" width="24.5" height="13"/>
</dimensions>
<transformationPoint>
<geom:Point x="0.5" y="0.5"/>
</transformationPoint>
</Source>
</source>

<Keyframe index="0">
<tweens>
<SimpleEase ease="0"/>
</tweens>
</Keyframe>

<Keyframe index="29" x="130"/>
</Motion>;
motion2=new Motion2();
this.addChild(motion2);
motion2.addEventListener(MouseEvent.CLICK, onClick);
}
public function onClick(e:MouseEvent):void{
trace("click");
var motion2_animator:Animator = new Animator(this.motion2_xml, this.motion2);
motion2_animator.play();
}
}
}


В чем проблема или что я делаю неверно?

etc
16.05.2007, 16:41
Исходник в студию.

NewMan_by
16.05.2007, 16:56
А вот исходник
http://newman.at.tut.by/temp.zip

etc
16.05.2007, 17:19
Фиг его знает, чего он не хочет ехать, пришлось ручками заставить:
package {
import flash.display.*;
import flash.events.*;
import fl.motion.*;
[SWF(width="910", height="650", backgroundColor="#cccccc", frameRate="12")]
public class Temp extends Sprite{
private var animator:Animator;
private var motion:Motion;
public function Temp(){
var motion2_xml:XML =<Motion duration="30" xmlns="fl.motion.*" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*">
<source>
<Source frameRate="12" x="12.25" y="6.5" scaleX="1" scaleY="1" rotation="0" elementType="movie clip" symbolName="motion2">
<dimensions>
<geom:Rectangle left="0" top="0" width="24.5" height="13"/>
</dimensions>
<transformationPoint>
<geom:Point x="0.5" y="0.5"/>
</transformationPoint>
</Source>
</source>

<Keyframe index="0">
<tweens>
<SimpleEase ease="0"/>
</tweens>
</Keyframe>

<Keyframe index="29" x="130"/>
</Motion>;
var motion2:Motion2 = new Motion2();
motion2.name = 'motion2';

animator = new Animator(motion2_xml);
motion = new Motion(motion2_xml);
animator.target = motion2;
this.addChild(motion2);

motion2.addEventListener(MouseEvent.CLICK, onClick);
}
public function onClick(e:MouseEvent):void{
addEventListener(Event.ENTER_FRAME,enterFrameHandler);
}
private function enterFrameHandler(e:Event):void {
if (animator.time<motion.duration) {
animator.time++;
} else {
removeEventListener(Event.ENTER_FRAME,enterFrameHandler);
}
}
}
}

NewMan_by
16.05.2007, 18:31
Спасибо!!!!
Попробовал вот так, тоже работает

package {
import flash.display.*;
import flash.events.*;
import fl.motion.*;
[SWF(width="910", height="650", backgroundColor="#cccccc", frameRate="12")]
public class Temp extends Sprite{
private var animator:Animator;
private var motion:Motion;
public function Temp(){
var motion2_xml:XML =<Motion duration="30" xmlns="fl.motion.*" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*">
<source>
<Source frameRate="12" x="12.25" y="6.5" scaleX="1" scaleY="1" rotation="0" elementType="movie clip" symbolName="motion2">
<dimensions>
<geom:Rectangle left="0" top="0" width="24.5" height="13"/>
</dimensions>
<transformationPoint>
<geom:Point x="0.5" y="0.5"/>
</transformationPoint>
</Source>
</source>

<Keyframe index="0">
<tweens>
<SimpleEase ease="0"/>
</tweens>
</Keyframe>

<Keyframe index="29" x="130"/>
</Motion>;
var motion2:Motion2 = new Motion2();
motion2.name = 'motion2';

animator = new Animator(motion2_xml);
motion = new Motion(motion2_xml);
animator.target = motion2;
this.addChild(motion2);

motion2.addEventListener(MouseEvent.CLICK, onClick);
}
public function onClick(e:MouseEvent):void{
animator.play();
}
}
}

etc
16.05.2007, 18:46
Тогда motion не нужен.

Annihilator
23.05.2007, 14:07
А если у меня начальные и конечные координаты хранятся в переменных, как их подставить в motion_XML ?

etc
23.05.2007, 15:24
Отредактировать или собрать XML в рантайме.

NewFolder
08.07.2008, 13:04
Извиняюсь, что пишу в столь древней теме, но вчера долго долбался с этой же проблемой.

Оказалось все дело в том, что объект animator объявляется в методе. В этом случае, он будет играть только один кадр, поскольку скорее всего ссылка на объект убивается. Поэтому animator нужно сделать параметром документ класса.
Надеюсь, кому-то поможет