Question

alt text
(source: flickr.com)

Hi again everyone :) So today I'm trying to basically create a simple glow effect on button rollOver. I may be over complicating things, but the way I'm going about this is by having 2 movieClips(default state and over state).

First I add the default state to the stage, next I add the rollOver state to the stage, but at a depth of 0 and alpha set to 0 as well. Now I want the rollOver state to swap depths with the default state as well as animate up to full alpha using the TweetLite class so I get a nice smooth transition.

I'm getting an error right now, but heres my code:

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

The error I'm getting on rollOver :(

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller. at flash.display::DisplayObjectContainer/setChildIndex() at test_fla::MainTimeline/sendToTop()

I don't understand what the error means by the supplied DisplayObject must be a child of the caller?

Was it helpful?

Solution

Based on what your trying to accomplished you don't have to manage depths. Essentially you can just add your rollover effect inside the shopButton and then once rolled over the shopButton, animate the glow. I udpated your code with the following:

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");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top