如何使用Action Script在Flash中绘制对角线?我使用补间动画制作动画,然后我尝试从补间动画生成动作脚本,但动画从屏幕中间开始,然后绘制它。它应该从左角开始,因为它是在常规动画中制作的。这是它生成的动作脚本:
import fl.motion.Animator;
var laser_xml:XML = <Motion duration="75" xmlns="fl.motion.*" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*">
<source>
<Source frameRate="25" x="13.6" y="13.25" scaleX="1" scaleY="1" rotation="0" elementType="drawing object">
<dimensions>
<geom:Rectangle left="10" top="10" width="7.25" height="6.5"/>
</dimensions>
<transformationPoint>
<geom:Point x="-1.3793103448275863" y="-1.5384615384615385"/>
</transformationPoint>
</Source>
</source>
<Keyframe index="0"/>
<Keyframe index="74" x="188.70000000000002" y="189.05"/>
</Motion>;
var laser_animator:Animator = new Animator(laser_xml, laser);
laser_animator.play();
答案 0 :(得分:1)
不确定您是否询问如何修改生成的代码,或仅使用AS3进行修改。如果是后者,这会给你带来理想的效果。请注意,使用补间库(如TweenLite或GTween)会更清晰:
var s:Shape = new Shape();
addChild(s);
var startPoint:Point = new Point();
var endPoint:Point = new Point();
var prog:Number = 0;
var frames:int = 200;
animateLine(100,100,50,50);
function animateLine(startX:Number, startY:Number, endX:Number, endY:Number, time:Number = 120):void {
startPoint.x = startX;
startPoint.y = startY;
endPoint.x = endX;
endPoint.y = endY;
frames = time;
prog = 0;
this.addEventListener(Event.ENTER_FRAME, tick);
}
function drawLineTick(progress:Number):void{
s.graphics.clear();
s.graphics.lineStyle(3,0xFF0000);
s.graphics.moveTo(startPoint.x,startPoint.y);
s.graphics.lineTo(startPoint.x + ((endPoint.x - startPoint.x) * progress), startPoint.y + ((endPoint.y - startPoint.y) * progress));
}
function tick(e:Event):void {
trace("tick",prog);
if(prog >= frames){
this.removeEventListener(Event.ENTER_FRAME, tick);
}
drawLineTick(prog / frames);
prog += 1;
}