0

各スライド/ページがムービークリップであり、スライド アニメーションを介して遷移するスライドショー スタイルのプレゼンテーションを作成しようとしています。私が抱えている問題は、ラグの問題を防ぐためにすべてのムービークリップを一度にステージに上げたくないということです。これは、私が達成しようとしているものの例です。

  • 現在のページはページ A、次へボタンをクリック
  • ページ B は、addChild を使用してステージに配置されます (ただし、ビューの外に配置されます)。
  • ページ A が目に見えるステージから滑り落ちる
  • ページ B が目に見えるステージにスライド
  • ページ A は、removeChild を使用してステージから削除されます - これは私が問題を抱えている場所です。
//greensock stuff
import com.greensock.*;
import com.greensock.easing.*;

//buttons that navigate to next and previous slides
prevBtn.addEventListener(MouseEvent.CLICK,prevClicked,false,0,true);
nextBtn.addEventListener(MouseEvent.CLICK,nextClicked,false,0,true);

//setting up array of all the pages
var pageArray:Array = [page1, page2, page3, page4, page5];
var currentArray:Number = 0;

//defining the first page and placing it on the stage
var currentPage:MovieClip = new pageArray[currentArray];
addChild(currentPage);



function nextClicked(event:MouseEvent):void{
    //check to ensure it is not the last page
    if (currentArray < pageArray.length - 1){
            //define the current slide as oldPage
            var oldPage:MovieClip = new pageArray[currentArray];
            currentArray++;
            //define the next slide as currentPage and place on stage
            var currentPage:MovieClip = new pageArray[currentArray];
            addChild(currentPage);
            currentPage.x = 1024;
            TweenMax.to(currentPage, 1, {x:0});
            TweenMax.to(oldPage, 1, {x:-1024,onComplete:removeChild,onCompleteParams:[oldPage]});
    }
}



function prevClicked(event:MouseEvent):void{
    //check to ensure it is not the first page
    if (currentArray > 0){
            //define the current slide as oldPage
            var oldPage:MovieClip = new pageArray[currentArray];
            currentArray--;
            //define the next slide as currentPage and place on stage
            var currentPage:MovieClip = new pageArray[currentArray];
            addChild(currentPage);
            currentPage.x = -1024;
            TweenMax.to(currentPage, 1, {x:0});
            TweenMax.to(oldPage, 1, {x:1024,onComplete:removeChild,onCompleteParams:[oldPage]});    }
}
4

2 に答える 2

1

あなたの「oldPage」は、最初のように、ステージ/ムービークリップにまだ追加されていない可能性があります。

したがって、代わりに:

TweenMax.to(oldPage, 1, {x:-1024,onComplete:removeChild,onCompleteParams:[oldPage]});

削除する前に、子がまだ存在するかどうかを最初に確認することを検討してください。これには、次のような新しい関数を呼び出す必要があります。

(未テストのコード)

TweenMax.to(oldPage, 1, {x:-1024,onComplete:tryRemoveChild,onCompleteParams:[oldPage]});

function tryRemoveChild(page:MovieClip):void {
   if(contains(page)){ //Check if child is still there
       removeChild(page); //It is, so remove
   } //Otherwise there is no child to currently remove
}
于 2012-01-27T06:49:14.967 に答える
0

oldPageをインスタンス化すると、そのクラスの新しいインスタンスが作成されます(または、少なくともそれが私には見えます)。そのページはステージ上にあるものと同じではありません。

コンストラクターで、変数currentPageを、ステージ上にあるページのインスタンス変数(オブジェクトプロパティで呼び出したもの)に設定します。次に、nextClickedで、追加される新しいページにリセットする前に、currentPageをoldPageに保存します。

FWIWの慣例では、クラス名は常に大文字になります。これを行っていれば、page1、page2などがインスタンス化するクラスであることを確認するのが簡単になります。

また、インスタンスはフレーム1の前にムービーにコンパイルされるため、起動時にステージ上にインスタンスがないため、おそらく多くの節約にはならないことに注意してください。[フレーム1に埋め込む]ボタンをオフにしても、クラスでそれらを参照します。フレーム1でコンパイルされるファイルは、フレーム1でコンパイルするように強制します。

=======================================変数をインスタンスに設定することに関する質問に答えるために編集

flaファイルのステージでオブジェクトをクリックした場合は、プロパティパネルでインスタンス名を確認してください。これがステージ上のインスタンスの名前です。名前がない場合は、名前を付けます。'ステージインスタンスを自動的に宣言する'がオンになっている場合は、すべて設定されています。そうでない場合は、ファイルの先頭に変数宣言を追加して、そのインスタンス名を変数として使用できるようにする必要があります。

さて、あなたのflaファイルのドキュメントクラスで(私はあなたが上に貼り付けたコードであると思います):

public function YourDocumentClassName() {
    super();
    currentPage = theNameofThatInstance;
}

nextClickedは、次のように変更されます。

function nextClicked(event:MouseEvent):void{
     //check to ensure it is not the last page
     if (currentArray < pageArray.length - 1){
             //define the current slide as oldPage
             var oldPage:MovieClip = currentPage;
             currentArray++;//may also want to consider checking for past the end of the array and starting at the beginning
             //define the next slide as currentPage and place on stage
             var currentPage:MovieClip = new pageArray[currentArray];
             addChild(currentPage);
             currentPage.x = 1024;
             TweenMax.to(currentPage, 1, {x:0});
             TweenMax.to(oldPage, 1, {x:-1024,onComplete:removeChild,onCompleteParams:[oldPage]});
     }
 }

グラフィックが大きい場合や動く場合は、ステージ上に複数のグラフィックがあるとパフォーマンスの問題が発生する可能性がありますが、読み込みの問題を回避しようとしていると思います。

于 2012-01-27T13:49:12.670 に答える