AS3.0在函数外怎样同时得到a1,a2,b1,b2参数package {import flash.display.MovieClip;import flash.display.Sprite;import flash.geom.Point;import flash.events.MouseEvent;import flash.events.DataEvent;import flash.utils.Timer;public cl

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 09:28:00

AS3.0在函数外怎样同时得到a1,a2,b1,b2参数package {import flash.display.MovieClip;import flash.display.Sprite;import flash.geom.Point;import flash.events.MouseEvent;import flash.events.DataEvent;import flash.utils.Timer;public cl
AS3.0在函数外怎样同时得到a1,a2,b1,b2参数
package {

import flash.display.MovieClip;
import flash.display.Sprite;
import flash.geom.Point;
import flash.events.MouseEvent;
import flash.events.DataEvent;
import flash.utils.Timer;


public class Trowball extends MovieClip {
private var p1:Point;
private var p2:Point;
private var v1:Number;
private var v2:Number;

 public function Trowball() {

var ball=new BALL();
addChild(ball);
ball.x=stage.stageHeight/2;
ball.y=stage.stageWidth/2;


function down(evt:MouseEvent):void{
evt.target.startDrag();
 p1=new Point(mouseX,mouseY);
//p1.x=mouseX;
//p1.y=mouseY;

 var date:Date=new Date();
 var a1:Number=date.seconds;
 var b1:Number=date.milliseconds;


trace();
trace("移动前坐标"+p1);
trace("鼠标移动秒数"+a1);
trace("鼠标移动毫秒数"+b1);
}

 function up(evt:MouseEvent):void{
evt.target.stopDrag();
 p2=new Point(mouseX,mouseY);
 var date:Date=new Date();
 var a2:Number=date.seconds;;
 var b2:Number=date.milliseconds;

trace("移动后坐标"+p2);
trace("鼠标移动秒数"+a2);
trace("鼠标移动毫秒数"+b2);


}



ball.addEventListener(MouseEvent.MOUSE_DOWN,down);
ball.addEventListener(MouseEvent.MOUSE_UP,up);


 }
}

}

AS3.0在函数外怎样同时得到a1,a2,b1,b2参数package {import flash.display.MovieClip;import flash.display.Sprite;import flash.geom.Point;import flash.events.MouseEvent;import flash.events.DataEvent;import flash.utils.Timer;public cl
首先你要明白,函数内的变量是局部变量,只能在函数内调用,函数外是不能调用的,要想让函数内的变量让函数外调用,必须引用其值,你可以声明一个类全局变量,将函数内变量的值传递给这个全局变量就可以了.具体是这样做的:
package {
\x05
\x05import flash.display.MovieClip;
\x05import flash.display.Sprite;
\x05import flash.geom.Point;
\x05import flash.events.MouseEvent;
\x05import flash.events.DataEvent;
\x05import flash.utils.Timer;
\x05
\x05
\x05public class Trowball extends MovieClip {
\x05\x05private var p1:Point;
\x05\x05private var p2:Point;
\x05\x05private var v1:Number;
\x05\x05private var v2:Number;
\x05\x05private var ga1:Number;
private var gb1:Number;
private var ga2:Number;
private var gb2:Number;
\x05 public function Trowball() {
\x05\x05
\x05\x05var ball=new BALL();
\x05\x05addChild(ball);
\x05\x05ball.x=stage.stageHeight/2;
\x05\x05ball.y=stage.stageWidth/2;
\x05\x05
\x05\x05\x05
\x05\x05function down(evt:MouseEvent):void{
\x05\x05\x05evt.target.startDrag();
\x05\x05 p1=new Point(mouseX,mouseY);
\x05\x05\x05//p1.x=mouseX;
\x05\x05\x05//p1.y=mouseY;
\x05\x05\x05
\x05\x05 var date:Date=new Date();
\x05\x05 var a1:Number=date.seconds;
ga1=a1;
\x05 var b1:Number=date.milliseconds;
gb1=b1;
\x05\x05
\x05\x05\x05trace();
\x05\x05\x05trace("移动前坐标"+p1);
\x05\x05\x05trace("鼠标移动秒数"+a1);
\x05\x05\x05trace("鼠标移动毫秒数"+b1);
\x05\x05\x05\x05}
\x05
\x05 function up(evt:MouseEvent):void{
\x05\x05\x05evt.target.stopDrag();
\x05\x05 p2=new Point(mouseX,mouseY);
\x05\x05 var date:Date=new Date();
\x05\x05 var a2:Number=date.seconds;;
\x05 var b2:Number=date.milliseconds;
\x05\x05 ga2=a2;
gb2=b2;
\x05\x05\x05trace("移动后坐标"+p2);
\x05\x05\x05trace("鼠标移动秒数"+a2);
\x05\x05\x05trace("鼠标移动毫秒数"+b2);
\x05\x05\x05
\x05\x05
\x05\x05}
\x05\x05
\x05\x05
\x05\x05
\x05\x05ball.addEventListener(MouseEvent.MOUSE_DOWN,down);
\x05\x05ball.addEventListener(MouseEvent.MOUSE_UP,up);
\x05\x05
\x05
\x05 }
\x05}
\x05
}
这样你就可以在类内任何地方调用这些值了.只是换成了ga1,ga2,gb1,gb2;