PDA

View Full Version : create an instance name in AS3



nwglow
May 6th, 2009, 01:11 PM
I have a movieclip called bg_mc. I don't want bg_mc to show up until I click the btn. When I click the btn it will perform a wipe.

Currently I have bg_mc on stage because I need to access its instance name. I can't remember how to create an instance name in AS3. Please HELP!


-----------------------------------------------------
import fl.transitions.*;
import fl.transitions.easing.*;

click_btn.addEventListener(MouseEvent.CLICK, loadBg);

function loadBg(evt:MouseEvent):void {
TransitionManager.start(bg_mc, {type:Wipe, direction:Transition.IN, duration:1, easing:Strong.easeOut, startPoint:4});
}

akiersky
May 6th, 2009, 01:53 PM
if you declare the instance in your code like:


private var big_mc:MovieClip()

you will be able to access it from within that class (or frame action) once it is initialized:


big_mc = new MovieClip()
addChild(big_mc)

big_mc.x=100
big_mc.y=100


hope this helps!
ak

nwglow
May 6th, 2009, 03:05 PM
I modify the code a bit to make it work. It is working using graphics.drawRect.
I would like to use the bg_mc from the library instead of drawing it. How can this be done?

-----------------------------------------------------------
import fl.transitions.*;
import fl.transitions.easing.*;
var bg_mc:MovieClip = new MovieClip();

click_btn.addEventListener(MouseEvent.CLICK, loadBg);

function loadBg(evt:MouseEvent):void {
bg_mc.graphics.beginFill(0xcccccc);
bg_mc.graphics.drawRect(0, 0, 400, 300);
bg_mc.graphics.endFill();
bg_mc.x=75;
bg_mc.y=30;
addChild(bg_mc);

TransitionManager.start(bg_mc, {type:Wipe, direction:Transition.IN, duration:1, easing:Strong.easeOut, startPoint:4});
}