Copy link to clipboard
Copied
I Would create, with as3, a button with random pictures that change at random time.
Any advice?
Thanks.
Try using: this.addChild(this["image"+String(i)]);
Copy link to clipboard
Copied
What aspect of this do you have a problem with? What code have you tried that is not working?
Copy link to clipboard
Copied
Thank you Ned,
I'm a begginer of as3 so need basic instructions.
Copy link to clipboard
Copied
Can you provide a more detailed explanation of what you need the code to do? Someone might take a shot at doing it for you if you do.
I don't think you will be getting lessons thru this forum so you should look into finding some tutorials for the various elements that will be involved with the functionality you briefly describe. For random timing look into the Math.random method and the Timer class or the setTimeout() function. For the button look into MouseEvent listeners and event handlers. For the image loading look into the Loader class.
Copy link to clipboard
Copied
Thanks again Ned,
I sent an exemplification of the script.
Concerning the Timeout maybe I have solved.
I am currently staying at this point, I can not run a variable refers to the name of a bitmap (see below "this.addChild (image + i);".
//--------------------image 1
var imgA:BitmapData=new M1(3,3);
var image0:Bitmap=new Bitmap(imgA);
image0.x=30;
image0.y=50;
//--------------------image 2
var imgB:BitmapData=new M2(3,3);
var image1:Bitmap=new Bitmap(imgB);
//this.addChild(imageA);
image1.x=130;
image1.y=50;
button_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame);
function fl_ClickToGoToAndStopAtFrame(event:MouseEvent):void
{
var i = Math.floor(Math.random()*2);
var imgC:BitmapData=new M1(3,3);
image0.x=270;
image0.y=50;
this.addChild(image+i); //this doesn't work ____________________________________
trace(i);
}
button_2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame2);
function fl_ClickToGoToAndStopAtFrame2(event:MouseEvent):void
{
{
var i = Math.floor(Math.random()*2);
var imgC:BitmapData=new M1(3,3);
image1.x=270;
image1.y=50;
this.addChild(image1);
}
}
Copy link to clipboard
Copied
Try using: this.addChild(this["image"+String(i)]);
Copy link to clipboard
Copied
Thank you Ned!!!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now