1

替代文字
(来源:flickr.com

大家好 :) 所以今天我试图在按钮翻转上创建一个简单的发光效果。我可能会让事情变得过于复杂,但我要解决的方法是拥有 2 个电影剪辑(默认状态和过度状态)。

首先,我将默认状态添加到舞台,接下来我将翻转状态添加到舞台,但深度为 0,alpha 也设置为 0。现在,我希望 rollOver 状态与默认状态交换深度,并使用 TweetLite 类动画到完整的 alpha,这样我就可以得到一个很好的平滑过渡。

我现在遇到错误,但这是我的代码:

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

我在翻转时遇到的错误:(

ArgumentError:错误 #2025:提供的 DisplayObject 必须是调用者的子对象。在 flash.display::DisplayObjectContainer/setChildIndex() 在 test_fla::MainTimeline/sendToTop()

我不明白提供的 DisplayObject 必须是调用者的孩子的错误意味着什么?

4

1 回答 1

1

根据您尝试完成的工作,您不必管理深度。本质上,您可以在 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");
}
于 2009-09-10T17:08:38.553 回答