←  Adobe Flash

Pixel2Life Forum

»

Actionscript 3 (Deleting Loaders Onstage C...

govjmal's Photo govjmal 13 Jun 2011

Hi, I'm having problems with deleting what a variable creates on stage!

I have a random image loader as seen below.
This creates a random image from the list I give it (only 4 in this example) and puts that picture on the stage.
______________________________________…
var imageLoader:Loader = new Loader();

var _pictureArray:Array = ["word0.png", "word1.png", "word2.png" ,"word3.png"];

var _whatPicture:Number = Math.floor(Math.random() * 4);
trace("_whatPicture = "+_whatPicture);

imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE,onComplete);
imageLoader.load(new URLRequest(_pictureArray[_whatPicture]));

function onComplete(e:Event):void{
var _image:Bitmap = Bitmap(imageLoader.content);
_image.x=180;
_image.y=82;
var _bitmap:BitmapData = _image.bitmapData;
addChild(_image);
}
______________________________________…

Depending on the image the right or left door is the correct door (tr is the left doors name).
The code below works fine, it even inserts the _whatPicture randomly again but the problem is the new picture overlaps the old picture, I can't figure out what to type so it will delete / remove the first _image, so that the new image is the only one there.
Here is the code for the left door:
______________________________________…
if (tr.hitTestObject(player)
&& (_whatPicture==1||_whatPicture==3||))
{
trHit = true
txtText.text = "CORRECT (red)";
tr.y = tr.y + 206;
tb.y = tb.y + 206;
player.y = 230
player.x = 470
var _whatPicture:Number = Math.floor(Math.random() * 203)
imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE,onComplete);
imageLoader.load(_pictureArray[_whatPicture]);
______________________________________…

Thanks!
Quote