Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Button with random time and random pictures

Contributor ,
Sep 23, 2014 Sep 23, 2014

I Would create, with as3, a button with random pictures that change at random time.

Any advice?

Thanks.

TOPICS
ActionScript
363
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 23, 2014 Sep 23, 2014

Try using:  this.addChild(this["image"+String(i)]);

Translate
LEGEND ,
Sep 23, 2014 Sep 23, 2014

What aspect of this do you have a problem with?  What code have you tried that is not working?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 23, 2014 Sep 23, 2014

Thank you Ned,

I'm a begginer of as3 so need basic instructions.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 23, 2014 Sep 23, 2014

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 23, 2014 Sep 23, 2014

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);

  }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 23, 2014 Sep 23, 2014

Try using:  this.addChild(this["image"+String(i)]);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 25, 2014 Sep 25, 2014
LATEST

Thank you Ned!!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines