FLash: Erro ao tentar usar setChildIndex e TweenLite para criar um efeito de rolagem botão

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

Pergunta

text alt
(fonte: flickr.com )

Oi novamente todos :) Então, hoje eu estou tentando basicamente criar um efeito de brilho simples no botão rollOver. Eu posso estar sobre complicar as coisas, mas a forma como eu vou sobre isso é por ter 2 MovieClips (estado padrão e mais de estado).

Primeiro eu adicionar o estado padrão para o palco, ao lado eu adiciono o estado de rolagem para o palco, mas a uma profundidade de 0 e alfa set a 0 também. Agora eu quero que o estado de rolagem a profundidades de swap com o estado padrão, bem como animar até alpha completo usando a classe TweetLite assim que eu conseguir uma transição suave agradável.

Estou recebendo um erro agora, mas aqui está o meu código:

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

O erro que eu estou recebendo em rollOver: (

ArgumentError: Erro # 2025: O DisplayObject fornecido deve ser filho do chamador. em flash.display :: DisplayObjectContainer / setChildIndex () em test_fla :: MainTimeline / sendToTop ()

Eu não entendo o que significa o erro pelo DisplayObject fornecido deve ser filho do chamador?

Foi útil?

Solução

Com base no que o seu tentando conseguido você não tem que gerenciar profundidades. Essencialmente, você pode simplesmente adicionar seu efeito de rolagem dentro do shopButton e, em seguida, uma vez rolou o shopButton, animar o brilho. I udpated seu código com o seguinte:

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");
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top