我寫了一些代碼,是AS3。我的目標是點擊MainTimeline階段並在功能runDraw()
內運行trace()
。目前,MOUSE_DOWN事件永遠不會被觸發,我無法弄清楚。在AS3中沒有觸發Mouse_down事件
代碼更新:
package circles
{
import flash.display.Sprite;
import flash.events.*;
import flash.geom.Point;
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
public class Circles extends Sprite
{
var circCentre:Sprite = new Sprite();
var circOuter:Sprite = new Sprite();
var point:Sprite = new Sprite();
trace("Class stuff initilized");
function Circles():void
{
this.addEventListener(MouseEvent.MOUSE_DOWN, runDraw);
trace("Constructor done");
}
function runDraw(e:MouseEvent):void
{
trace("runDraw(e)");
// centre circle draw and add to timeline
circCentre.graphics.lineStyle(3, 0x000000);
circCentre.graphics.beginFill(0xFF6600);
circCentre.x = e.stageX;
circCentre.y = e.stageY;
circCentre.graphics.drawCircle(e.stageX, e.stageY, 100);
circCentre.graphics.endFill();
this.addChild(circCentre);
trace("mc.addChild(circCentre)");
// smaller outer circle
circCentre.addChild(circOuter);
// attach to parent;
circOuter.graphics.lineStyle(1, 0xDD2211);
circOuter.graphics.beginFill(0x66FF00);
circOuter.x = 200;
circOuter.y = e.stageY;
circOuter.graphics.drawCircle(200, e.stageY, 50);
circOuter.graphics.endFill();
// the draw point;
circOuter.addChild(point);
point.graphics.moveTo(5, 0);
point.graphics.lineTo(5, 10);
point.graphics.moveTo(0, 5);
point.graphics.lineTo(10, 5);
point.x = 50;
point.y = 90;
stage.addEventListener(Event.ENTER_FRAME, rotationDraw);
stage.addEventListener(MouseEvent.MOUSE_UP, finish);
}
public function rotationDraw(e:Event):void
{
circCentre.rotation++;
circOuter.rotation++;
}
public function finish(e:MouseEvent):void
{
stage.removeEventListener(Event.ENTER_FRAME, rotationDraw);
}
}
}
非常感謝。
AHH!所以需要從時間線通過參考舞臺......真棒哥們,謝謝! – Alex 2011-03-30 02:48:45
沒有戲劇的,我很高興它幫助 - 我喜歡這個效果順便提一下 – Chris 2011-03-30 02:50:33
謝謝,它還沒有出來,還有一兩天的時間。 – Alex 2011-03-30 03:00:50