我有5层,每层有符号:a,b,c,d和e。 我试图找出当你将鼠标悬停在b上时如何将动作波纹管应用于a,c,d和e。
还有另一个类似于'gotoAndStop(0)的动作; '而不是直接进入第0帧它会回到原来的状态吗?
链接到.Fla http://www.fileden.com/files/2012/11/27/3370853/Untitled-2.fla
stop();
stage.addEventListener(MouseEvent.MOUSE_OVER, playMovie); function playMovie(event) { play(); }
stage.addEventListener(MouseEvent.MOUSE_OUT, stopMovie); function stopMovie(event) { gotoAndStop(0); }
stop();
由于
答案 0 :(得分:1)
修改强>
在查看你的.fla之后,这里有什么遗漏/错位:
闪存中的图层不代表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
}
}