R – How to reference a bitmap on the stage in actionscript

actionscript-3flash

How do you reference a bitmap on the stage in flash using actionscript 3?

I have a bitmap on the stage in flash and at the end of the movie I would like to swap it out for the next in the sequence before the movie loops. in my library i have 3 images, exported for actionscript, with the class name img1/img2/img3. here is how my layers in flash are set out.

layer 5 : mask2:MovieClip
layer 4 : img2:Bitmap
layer 3 : mask1:MovieClip
layer 2 : img1:Bitmap
layer 1 : background:Bitmap

at the end of the movie I would like to swap img1 with img2, so the movie loops seamlessly, then ideally swap img2 (on layer 4) with img3 and so on until I get to the end of my images.

but I can not find out how to reference the images that have already been put on the stage (in design time), any one have any idea of how to do this?

The end movie will hopefully load images dynamically from the web server (I have the code for this bit) and display them as well as img1/img2/img3.

Any help would be appreciated.

EDIT:

@81bronco , I tried this but the instance name is greyed out for graphics, it will only allow me to do it with movieclips and buttons. I half got it to work by turning them into moveclips, and clearing the images in the moveclip out before adding a new one (using something simpler to what vanhornRF suggested), but for some odd reason when the mask kicks in the images I cleared out come back for the mask animation.

Best Answer

To reference something on the stage, you need to give the stage instance a name - not give the symbol in the library a class name.

Click on the item on the stage and look at the properties panel. There should be a text entry box just above the entry boxes for the item's dimensions. Enter a name there.

Elsewhere in your code, you can then refer to that item on stage by it's instance name.

Related Topic