A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: random picture through click event

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    13

    random picture through click event

    Hey

    My Question is:

    I want to make a click event and by that event from 10 pictures a randomly chosen picture is shown/appears. So always when i click that button randomly a picture will appear.

    how do I write that?

  2. #2
    Junior Member
    Join Date
    Dec 2013
    Location
    Indiana
    Posts
    5
    Hello Zipped. I'm not sure whether or not I'm answering too late, but here it is anyways:

    What you need to do is create two separate symbols, the one will be the button and the other will be your ten pictures. Make the pictures symbol ten frames long, and have each frame contain a picture. Add the method stop(); to the first frame of this symbol. The instance name of the button should be "button" and the instance name of the pictures symbol should be "pictures". Next add this code to frame 1 of the timeline:

    button.addEventListener(MouseEvent.CLICK,new_pictu re);
    function new_picture(e:MouseEvent){
    picture.gotoAndStop(Math.round(1+(10-1)*Math.random()));
    }

    Cheers,
    Drake Swartzy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center