A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Random Movieclips onto the stage

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    1

    Random Movieclips onto the stage

    Hi I am wondering if someone can help me.
    I am basically trying to make a quiz.
    I basically want to add two movie clips to the stage randomly.
    When the button play is clicked it generates two movie clips which represent two numbers, they then have to work out what the answer is.
    At the moment i have this code but i cant work out how i can randomly add them to the stage.
    Code:
    import flash.events.MouseEvent;
    
    stop();
    
    btnNumericHelp.addEventListener(MouseEvent.CLICK, onButtonClick3);
    btnPlay.addEventListener(MouseEvent.CLICK,onButtonClick5);
    
    function onButtonClick3 (event:MouseEvent): void
    {
    	gotoAndPlay(1,"Scene 4");
    }
    
    
    
    function onButtonClick5 (event:MouseEvent):void
    {
    	trace ("Pressed");
    	
    	for (var i:int = 0; i < 10; i++)
    	{
    		var Beer:MovieClip = new BeerMC();
    		Beer.name = "Beer" + i;
    		trace (Beer.name);
    		
    		var Cocktail:MovieClip = new CocktailMC();
    		Cocktail.name = "Cocktail" + i;
    		trace (Cocktail.name);
    	}
    	
    	
    }

  2. #2
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    You need to set random numbers to the the x and y properties. eg

    yourMovieClip.x = Math.random() * stage.stageWidth;
    yourMovieClip.y = Math.random() * stage.stageHeight;
    Last edited by ilike2; 01-31-2013 at 08:34 AM. Reason: typo

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    1
    Hi ilike2! I would like to thank you for your blog. I've been checking it out since I started Flash.It has been a really helpful reference specially in AS3. It's quite a relief that you are active in this forum because I have a question to ask. Hehe.

    When you enter the code, ball_mc= Math.random() * stage.stageWidth;
    ball_mc = Math.random() * stage.stageHeight;
    which the ball_mc is just a simple ball converted to movie clip, how do you stop it from becoming random? And when you over the mouse, the ball would be in random position again?

    Thank you!

  4. #4
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    Try using this code. It will disable any interaction with the movie clip.

    ball_mc.mouseEnabled = false;

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