0

a、b、c、d、e の 5 つのレイヤーがあり、それぞれにシンボルがあります。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();

ありがとう

4

1 に答える 1

1

編集

あなたの.flaを見た後、ここに欠けている/置き忘れられているものがあります:

  1. フラッシュのレイヤーは、zオーダー/深度以外の意味ではありません。コードでレイヤーを操作することはできません。すべてのアニメーションは同じタイムライン上にあるため、常に一緒に再生されます。個々のアイテムを他のアイテムなしでアニメーション化する場合は、(レイヤーだけでなく)独自のタイムラインでアニメーションを作成する必要があります。あなたはそれをダブルクリックすることによってあなたのシンボル自身のタイムラインにアクセスします-そこであなたのアニメーションをしてください。

  2. ステージ上にあるアイテムを参照するには、それらにインスタンス名を付ける必要があります。これを行うには、ステージ上にあるアイテムをクリックします。次に、プロパティパネルに、インスタンス名を入力できるフィールドがあります。以下のコードを機能させるには、それぞれ「a」、「b」、「c」、「d」、「e」のインスタンス名を付ける必要があります。これは、ライブラリのシンボル名とは異なります(同じ名前でもかまいません)。


これを行う1つの方法:

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);
        }
    }
}

タイムラインを逆方向に再生する良い方法はありませんが、それを行う方法はあります。そのような方法の1つ:

//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
    }
}
于 2012-11-27T21:06:53.403 に答える