フラッシュ:setChildIndexおよびTweenLiteを使用してボタンrollOverエフェクトを作成しようとするとエラーが発生します

StackOverflow https://stackoverflow.com/questions/1406363

質問

 alt text
(ソース: flickr.com

こんにちは皆さん:)それで、今日は基本的にボタンrollOverに単純なグローエフェクトを作成しようとしています。私は物事を複雑にしているかもしれませんが、私がこれについて行っている方法は、2つのmovieClips(デフォルト状態とオーバー状態)を持つことです。

最初にステージにデフォルト状態を追加し、次にrollOver状態をステージに追加しますが、深さ0でアルファも0に設定します。今度は、rollOver状態でデフォルトの状態と深度を交換し、TweetLiteクラスを使用してフルアルファまでアニメーション化することで、スムーズな移行を実現します。

現在エラーが発生していますが、コードは次のとおりです:

import gs.TweenLite;
import fl.motion.easing.*;
import flash.display.MovieClip;


var shopButton:MovieClip;
var shopButtonRoll:MovieClip;
var maxIndex:Number = this.numChildren - 1;

// Button - places the default state onto the stage
shopButton = new ShopButton();
shopButton.name = "shopButton";
shopButton.x = 262;
shopButton.y = 207;
shopButton.stop();
thumbsMov.addChild(shopButton);

// Button Glow - places rollOver state under the default and with 0 alpha
shopButtonRoll = new ShopButtonRoll();
shopButtonRoll.name = "shopButtonRoll";
shopButtonRoll.x = 262;
shopButtonRoll.y = 207;
shopButtonRoll.alpha = 0;
thumbsMov.addChildAt(shopButtonRoll, 0);

// Listeners

shopButton.addEventListener(MouseEvent.MOUSE_UP, shopClick);
shopButton.addEventListener(MouseEvent.ROLL_OVER, sendToTop);
shopButton.addEventListener(MouseEvent.ROLL_OUT, shopOff);
shopButtonRoll.addEventListener(MouseEvent.ROLL_OVER, shopOver);

// Button Actions 
// shopOver should bring rollOver to top and animate to 100%

function shopOver(event:MouseEvent):void
{
     TweenLite.to(shopButtonRoll, 1, {alpha:1});
}
function shopOff(event:MouseEvent):void
{
     // Code to animate back to 0 then change depth of rollOver to 0
}
function shopClick(event:MouseEvent):void
}
     trace("You clicked Shop");
}

// sendToTop Function
// Sent to top - depth change
function sendToTop(e:Event):void
{
     //this.setChildIndex(ShopButton(e.target), maxIndex);
     this.setChildIndex(e.currentTarget as MovieClip, maxIndex);
}

rollOverで表示されるエラー:(

ArgumentError:エラー#2025:指定されたDisplayObjectは、呼び出し元の子である必要があります。     flash.display :: DisplayObjectContainer / setChildIndex()で     test_fla :: MainTimeline / sendToTop()で

提供されたDisplayObjectがエラーの意味するところがわからないのは、呼び出し元の子である必要がありますか

役に立ちましたか?

解決

達成しようとしたことに基づいて、深さを管理する必要はありません。基本的に、shopButton内にロールオーバーエフェクトを追加してから、shopButtonの上にロールオーバーすると、グローをアニメーション化できます。コードを次のように更新しました。

import gs.TweenLite;
import fl.motion.easing.*;
import flash.display.MovieClip;


var shopButton:MovieClip;
var shopButtonRoll:MovieClip;

// Button - places the default state onto the stage
shopButton = new ShopButton();
shopButton.name = "shopButton";
shopButton.x = 262;
shopButton.y = 207;
shopButton.stop();
thumbsMov.addChild(shopButton);

// Button Glow - places rollOver state under the default and with 0 alpha
shopButtonRoll = new ShopButtonRoll();
shopButtonRoll.name = "shopButtonRoll";
shopButtonRoll.alpha = 0;
shopButton.addChild(shopButtonRoll);


// Listeners
shopButton.buttonMode = true;
shopButton.addEventListener(MouseEvent.MOUSE_UP, shopClick);
shopButton.addEventListener(MouseEvent.ROLL_OVER, shopOver);
shopButton.addEventListener(MouseEvent.ROLL_OUT, shopOff);

// Button Actions 
// shopOver should bring rollOver to top and animate to 100%

function shopOver(event:MouseEvent):void
{
     TweenLite.to(shopButtonRoll, 1, {alpha:1});
}
function shopOff(event:MouseEvent):void
{
    TweenLite.to(shopButtonRoll, 1, {alpha:0});
     // Code to animate back to 0 then change depth of rollOver to 0
}
function shopClick(event:MouseEvent):void
}
     trace("You clicked Shop");
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top