<p>How do you reference a bitmap on the stage in flash using actionscript 3?</p>

<p>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.</p>

<pre><code>layer 5 : mask2:MovieClip
layer 4 : img2:Bitmap
layer 3 : mask1:MovieClip
layer 2 : img1:Bitmap
layer 1 : background:Bitmap
</code></pre>

<p>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.</p>

<p>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?</p>

<p>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.</p>

<p>Any help would be appreciated.</p>

<p><strong>EDIT:</strong></p>

<p>@<a href="https://stackoverflow.com/questions/43354/how-do-you-reference-a-bitmap-on-the-stage-in-actionscript#43735">81bronco</a> , 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 <a href="https://stackoverflow.com/questions/43354/how-do-you-reference-a-bitmap-on-the-stage-in-actionscript#44347">vanhornRF</a> suggested), but for some odd reason when the mask kicks in the images I cleared out come back for the mask animation.</p>

[{'answer_id': 43477, 'author': 'bitbonk', 'author_id': 4227, 'author_profile': 'https://Stackoverflow.com/users/4227', 'pm_score': 1, 'selected': False, 'text': '<p>It should be something like this:</p>\n\n<pre><code>imageHolder.removeChild( imageIndex )\n</code></pre>\n\n<p>or</p>\n\n<pre><code>imageHolder.removeChildByName( imageName )\n</code></pre>\n\n<p>and after that</p>\n\n<pre><code>imageHolder.addChild( newImage )\n</code></pre>\n'}, {'answer_id': 43735, 'author': 'Raleigh Buckner', 'author_id': 1153, 'author_profile': 'https://Stackoverflow.com/users/1153', 'pm_score': 3, 'selected': True, 'text': "<p>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.</p>\n\n<p>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.</p>\n\n<p>Elsewhere in your code, you can then refer to that item on stage by it's instance name.</p>\n"}, {'answer_id': 44347, 'author': 'vanhornRF', 'author_id': 1945, 'author_profile': 'https://Stackoverflow.com/users/1945', 'pm_score': 0, 'selected': False, 'text': '<p>I would probably do something like this in your document class</p>\n\n<pre><code>for(var i:int=0; i&lt;numChildren; i++){\n    trace(getChildAt(i),"This is the child at position "+i);\n}\n</code></pre>\n\n<p>I do this because I still code in the flash IDE and its debugger is so very painful to get working most of the time it\'s easier to just trace variables out, so you can either use that for loop to print the object names of the items currently on your stage, or use a debugger program to find the objects as well.</p>\n\n<p>Now that you have the children and at what index they actually are at within the stage, you can reference them by calling getChildAt(int), you can removeChildAt(int), you can addChildAt(displayObject, int) and swapChildrenAt(int, int). The int in these arguments would represent the index position that was returned by your trace statement and the displayObject would obviously just represent anything you wanted to add to the stage or parent DisplayObject.</p>\n\n<p>Using those 4 commands you should be able to freely re-arrange any movieclips you have on stage so that they will appear to transition seamlessly.</p>\n\n<p>@81bronco One should definitely name your assets on stage if you want to uniquely reference them specifically to avoid any confusion if there ends up being a lot of items on stage</p>\n'}, {'answer_id': 44445, 'author': 'vanhornRF', 'author_id': 1945, 'author_profile': 'https://Stackoverflow.com/users/1945', 'pm_score': 0, 'selected': False, 'text': "<p>Hey Re0sless, when you remove those items from the stage do they have any event listeners attached to them, any timers or loaders? Any of those things can make an object stick around in flash's memory and not remove properly. Also on top of just removing the item, perhaps try nulling it as well? Sometimes that helps in clearing out its references so it can be properly destroyed.</p>\n\n<p>Of course it could also be something silly like removing the item at one instance doesn't remove the item from future frames as well, but I really don't think that's the case.</p>\n"}]
['https://Stackoverflow.com/questions/43354', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2098/']