Flash as3问题
希望哪位大大能给段代码,百度HI我也可,最好是能有点注释的,谢谢各位了~ 展开
前提条件见图片。
程序是写在as文件里边的,保存为test这个名字:
package {
import flash.text.TextField;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import com.greensock.TweenLite;
import com.greensock.easing.Expo;
import flash.geom.Point;
public class Test extends MovieClip {
private var rot:Number = 0;
private var juli:Number = 0;
private var mc:MovieClip;
private var btn1:MovieClip;
private var btn2:MovieClip;
private var _pp:Point = new Point;
private var _newPoint:Point = new Point;
private var _textRot:TextField;
private var _textJuli:TextField;
private var _oldPoint = new Point;
private var _can:Boolean = false;
public function Test() {
mc = clip_mc as MovieClip;
btn1 = btn1_mc as MovieClip;
btn2 = btn2_mc as MovieClip;
_textRot = rot_text as TextField;
_textJuli = juli_text as TextField;
btn1.buttonMode = btn2.buttonMode = true;
_oldPoint.x = mc.x;
_oldPoint.y = mc.y;
btn1.addEventListener(MouseEvent.CLICK, _onClick);
btn2.addEventListener(MouseEvent.CLICK, _relo);
}
private function _relo(e:MouseEvent):void
{
if (_can)
{
mc.x = _oldPoint.x;
mc.y = _oldPoint.y;
mc.rotation = 0;
graphics.clear();
}
}
private function _onClick(e:MouseEvent):void
{
_pp.x = mc.x;
_pp.y = mc.y;
rot = Number(_textRot.text);
juli = Number(_textJuli.text);
_newPoint.x = Math.floor(Math.cos(rot * Math.PI / 180) * juli)+_pp.x;
_newPoint.y = Math.floor(Math.sin(rot * Math.PI / 180) * juli)+_pp.y;
TweenLite.to(mc, 0.6, { rotation:rot, ease:Expo.easeOut, onComplete:_doit } );
_can = false;
}
private function _doit():void
{
TweenLite.to(mc, 3, { x:_newPoint.x, y:_newPoint.y, ease:Expo.easeOut,onComplete:_delEnter} );
graphics.lineStyle(1);
graphics.moveTo(_pp.x,_pp.y);
this.addEventListener(Event.ENTER_FRAME, _draw);
}
private function _delEnter():void
{
_can = true;
this.removeEventListener(Event.ENTER_FRAME, _draw);
}
private function _draw(e:Event):void
{
graphics.lineTo(mc.x,mc.y);
}
}
}
如果上边这段代码报错的话,应该是你没有安装TweenLite。那么就用下边这段代码:
package {
import flash.text.TextField;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.Regular;
import fl.transitions.TweenEvent;
import flash.geom.Point;
public class Test extends MovieClip {
private var rot:Number = 0;
private var juli:Number = 0;
private var mc:MovieClip;
private var btn1:MovieClip;
private var btn2:MovieClip;
private var _pp:Point = new Point;
private var _newPoint:Point = new Point;
private var _textRot:TextField;
private var _textJuli:TextField;
private var _oldPoint = new Point;
private var _can:Boolean = false;
public function Test() {
mc = clip_mc as MovieClip;
btn1 = btn1_mc as MovieClip;
btn2 = btn2_mc as MovieClip;
_textRot = rot_text as TextField;
_textJuli = juli_text as TextField;
btn1.buttonMode = btn2.buttonMode = true;
_oldPoint.x = mc.x;
_oldPoint.y = mc.y;
btn1.addEventListener(MouseEvent.CLICK, _onClick);
btn2.addEventListener(MouseEvent.CLICK, _relo);
}
private function _relo(e:MouseEvent):void
{
if (_can)
{
mc.x = _oldPoint.x;
mc.y = _oldPoint.y;
mc.rotation = 0;
graphics.clear();
}
}
private function _onClick(e:MouseEvent):void
{
_pp.x = mc.x;
_pp.y = mc.y;
rot = Number(_textRot.text);
juli = Number(_textJuli.text);
_newPoint.x = Math.floor(Math.cos(rot * Math.PI / 180) * juli)+_pp.x;
_newPoint.y = Math.floor(Math.sin(rot * Math.PI / 180) * juli)+_pp.y;
var xTween:Tween = new Tween(mc, "rotation", Regular.easeOut, mc.rotation, rot, 1 , true);
xTween.addEventListener(TweenEvent.MOTION_FINISH, _doit);
_can = false;
}
private function _doit(e:TweenEvent=null):void
{
var t1:Tween = new Tween(mc, "x", Regular.easeOut, mc.x, _newPoint.x, 1 , true);
var t2:Tween = new Tween(mc, "y", Regular.easeOut, mc.y, _newPoint.y, 1 , true);
t1.addEventListener(TweenEvent.MOTION_FINISH, _delEnter);
graphics.lineStyle(1);
graphics.moveTo(_pp.x,_pp.y);
this.addEventListener(Event.ENTER_FRAME, _draw);
}
private function _delEnter(e:TweenEvent=null):void
{
_can = true;
this.removeEventListener(Event.ENTER_FRAME, _draw);
}
private function _draw(e:Event):void
{
graphics.lineTo(mc.x,mc.y);
}
}
}
大哥在么?,你这个代码能用,谢谢了,不过我笨,如果箭头是向下的时候,就是↓这样,角度为0,是角度上再加减这个差的角度么……OK,已经搞定了,非常非常感谢你,我问了N多的人,都只会百度或者说理论,谢谢了,请受小弟一拜啊(*^__^*) !
2011-09-14