FLash: errore durante il tentativo di utilizzare setChildIndex e TweenLite per creare un effetto rollOver pulsante

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

Domanda

 alt text
(fonte: flickr.com )

Ciao a tutti :) Quindi oggi sto cercando di creare un semplice effetto bagliore sul pulsante di scorrimento. Potrei complicare le cose, ma il modo in cui sto andando avanti è avere 2 movieClips (stato predefinito e stato sopra).

Per prima cosa aggiungo lo stato predefinito allo stage, successivamente aggiungo lo stato rollOver allo stage, ma a una profondità di 0 e anche alpha impostato su 0. Ora desidero che lo stato rollOver cambi profondità con lo stato predefinito, nonché animare fino all'alfa completa utilizzando la classe TweetLite, in modo da ottenere una transizione graduale.

Al momento sto ricevendo un errore, ma ecco il mio codice:

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

Errore su rollOver :(

ArgumentError: Errore n. 2025: l'oggetto DisplayObject fornito deve essere figlio del chiamante.     at flash.display :: DisplayObjectContainer / setChildIndex ()     at test_fla :: MainTimeline / sendToTop ()

Non capisco cosa l'errore debba significare DisplayObject in dotazione deve essere figlio del chiamante?

È stato utile?

Soluzione

In base a ciò che stai cercando di realizzare non devi gestire le profondità. In sostanza, puoi semplicemente aggiungere il tuo effetto di rollover all'interno dello ShopButton e quindi, una volta rotolato sullo ShopButton, animare il bagliore. Ho ascoltato il tuo codice con il seguente:

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");
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top