2010-10-15 80 views
2

如何將當前目標放入影片剪輯?ActionScript 3.0 - 如何將當前目標放入影片剪輯?

如果我們可以將當前目標設置爲「selectMovieClip」變量,那麼我相信我們應該能夠旋轉或操縱它作爲MovieClip。

請複製下面的腳本,你會明白我的意思。目前我無法旋轉它。

請告訴我我的腳本有什麼問題。謝謝。

import flash.display.MovieClip; 

/*create multiple MovieClip*/ 
for(var i:int = 0; i < 10; i++){ 
    var widthSquare:int = 100; 
    var heightSquare:int = 100; 
    var square:MovieClip = new MovieClip(); 
    square.graphics.lineStyle(1,0x0000CC); 
    square.graphics.beginFill(0xCCCCCC); 
    square.graphics.drawRect(0,0,widthSquare,heightSquare); 
    square.graphics.endFill(); 
    square.name = "RotableClip_"+i; 
    square.x = 100 + (widthSquare*i); 
    square.y = 400; 
    addChild(square); 
} 

//SET MOVIECLIP 
var selectMovieClip;//declare veriable 
function onMousePress(evt:MouseEvent):void{ 
    if(evt.target.name.indexOf("RotableClip_")==0){//only allow RotableClip_ to rotate 
    selectMovieClip=evt; 
    trace("Selected movie clip" + evt.target.name); 
    } 
} 
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMousePress); 


//Rotate MovieClip 
function MouseMove(evt:Event):void{ 
    rotateTarget();//recreate the menu 
    } 
stage.addEventListener(MouseEvent.MOUSE_MOVE, MouseMove); 
function onMouseRelease(evt:MouseEvent):void { 
    rotateTarget() 
} 

//rotateTarget OR at onMousePress 
//How do we bring the movie clip into the below and rotate it. 
function rotateTarget(){ 
    selectMovieClip.rotation += 90; 
    trace("Rotate the movie clip"); 
} 

回答

1

在onMousePress(),您分配給selectMovieClip EVT,不evt.target!由於selectMovieClip沒有輸入,Flash不會拋出錯誤。另外,如果你跟蹤selectMovieClip而不是跟蹤evt.target.name,你會發現錯誤!

+0

那麼我沒有執行你的代碼,但我認爲PatrickS正在指導你的錯誤..嘗試並檢查。 – 2010-10-16 16:12:23

+0

那麼,我們如何將movieClip分配給「selectMovieClip」,這是實例名稱。 – dngo 2010-10-18 14:08:45

+0

我認爲它得到了它。 evt.target – dngo 2010-10-18 14:14:02