編輯
看着你的根後,這裏是缺少/放錯了地方:
flash中的圖層並不意味着任何o而不是z-階/深度。你不能在代碼中操作圖層。你所有的動畫都在同一時間線上,所以他們會一直玩。如果你想讓一個單獨的項目在沒有其他項目的情況下進行動畫製作,那麼你必須在它自己的時間線上進行動畫製作(而不僅僅是圖層)。雙擊它即可訪問符號自己的時間軸 - 在那裏做動畫。
要引用舞臺上的項目,您需要給它們一個實例名稱。您可以通過單擊舞臺上的項目來完成此操作,然後在屬性面板中可以放置實例名稱的字段。對於下面的代碼工作,你需要分別給他們一個實例名稱「a」,「b」,「c」,「d」,「e」。這與庫中的符號名稱不同(儘管它可以是相同的名稱)。你可以這樣做
方式一:
var btns:Vector.<MovieClip> = new Vector.<MovieClip>(); //create an array of all your buttons
btns.push(a,b,c,d,e); //add your buttons to the array
for each(var btn:MovieClip in btns){
btn.addEventListener(MouseEvent.MOUSE_OVER, btnMouseOver); // listen for mouse over on each of the buttons
btn.addEventListener(MouseEvent.MOUSE_OUT, btnMouseOut);
}
function btnMouseOver(e:Event):void {
for each(var btn:MovieClip in btns){ //loop through all your buttons
if(btn != e.currentTarget){ //if the current one in the loop isn't the one that was clicked
btn.play();
try{
btn.removeEventListener(Event.ENTER_FRAME,moveBackwards); //this will stop the backwards animation if running. it's in a try block because it will error if not running
}catch(err:Error){};
}
}
}
function btnMouseOut(e:Event):void {
for each(var btn:MovieClip in btns){ //loop through all your buttons
if(btn != e.currentTarget){ //if the current one in the loop isn't the one that was clicked
goBackwards(btn);
}
}
}
有向後播放時間軸沒有很好的方式,但也有辦法做到這一點。一種這樣的方式:
//a function you can call and pass in the item/timeline you want played backwards
function goBackwards(item:MovieClip):void {
item.stop(); //make sure the item isn't playing before starting frame handler below
item.addEventListener(Event.ENTER_FRAME, moveBackwards); //add a frame handler that will run the moveBackwards function once every frame
}
//this function will move something one frame back everytime it's called
function moveBackwards(e:Event):void {
var m:MovieClip = e.currentTarget as MovieClip; //get the movie clip that fired the event
if(m.currentFrame > 1){ //check to see if it's already back to the start
m.prevFrame(); //if not move it one frame back
}else{
m.removeEventListener(Event.ENTER_FRAME,moveBackwards); //if it is (at the start), remove the enter frame listener so this function doesn't run anymore
}
}
小側面說明:您gotoAndStop使用0,但基於幀不爲零,它開始於第1幀 –
@MarkKnol - 漂亮的抓 – BadFeelingAboutThis
順便說一下它不給任何錯誤,如果默認爲1. –