views:

38

answers:

4

I want to make a movieclip invisible initially but i dont want to set it manually within the properties in flash because i cant then see it on the scene.

I was hoping i could add some code like so:

MC Frame one.

this.onClipEvent(load)
{
this._alpha = 0;
}

but I cannot. How can i set the MC _alpha to 0 for all instances without adding it manually to each instance or setting it in the properties?

edit: or creating a class for it just to set the alpha.

A: 

If you want to do this by creating a subclass in actionscript 2, here's a great step-by-step tutorial from Adobe.

http://www.adobe.com/devnet/flash/articles/mc_subclasses_v2_04.html

The tutorial instructs you to add an onEnterFrame event handler, but you can ignore that and simply add the following code to the constructor.

If your classname is Ball then the code would look like this. (this is from step 4 in the tutorial).

dynamic class Ball extends MovieClip {

  function Ball() {
    this._alpha = 0;
  }
}
jessegavin
A: 

Maybe there's something I didn't understood correctly, but you just have to write something like this on your first frame :

yourFirstMovieClip._alpha = 0;
yourSecondMovieClip._alpha = 0;



If your MovieClips names are numbered (mc0, mc1, mc2, mc3...), you can use a loop to set the _alpha property to every clips. Let say you have 5 clips (mc0 to mc4) :

for( var i:Number = 0  ;  i < 5  ;  i++ )
{
    this["mc"+i]._alpha = 0;
}



If not, you can store every clips in an Array and them loop through it :

var clips:Array = [mcFirst, mcSecond, mcThird, mcFourth];
for( var i:Number = 0  ;  i < clips.length  ;  i++ )
{
   clips[i]._alpha = 0;
}
Zed-K
I wanted to write the code in one place inside the MC without naming the instances directly. That way i can just add as many MC's as i like and never have to worry about modifying the code.Thanks anyway.
Kohan
A: 

I am now using this code, which does what i want. But i hate it.

    var once:Boolean;

    if (once == null) {
        once = true;
        this._alpha = 0;
    }
Kohan
It's basically emulating the onClipEvent(Load)
Kohan
A: 

Another solution may be to put this line on the first frame of your MovieClip :

_alpha = 0;

Start your animation on the second frame, and add the following line on your last one :

gotoAndPlay( 2 );

So the code on the first frame is only executed one time.

Zed-K
I did consider this, and even tried it out. But i am adding to someone existing code. Something was causing it to re-execute regardless so hoped for another way of doing it.
Kohan