A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Calling Random Function

  1. #1
    Sonic the FlashHog geoffp08's Avatar
    Join Date
    May 2002
    Location
    Orlando
    Posts
    237

    Calling Random Function

    GDay FK, Ok, heres the deal... Ive got 4 MCs in the library all exported under the same name that call them in the array. What Im looking to do is have the timer randomly generate a time, than randomly attach a MC out of the array and play it. I have a 2 frames. the first frame is a menu screen, this code lies on the second frame. What happens is, after a random amount of time, it jumps back to frame ones menu screen? Not quite sure where its getting that crazy idea from. Anyways, if youre infinite knowledge can shed a little light on where I left turned Id appreciate it... thanks.
    Geoff
    Code:
    function pause(){
    	play();
    	clearInterval(timer);
    }
    DangerEvent = new Array();
    DangerEvent[1] = "BLMissile";
    DangerEvent[2] = "BRMissile";
    DangerEvent[3] = "TRMissile";
    DangerEvent[4] = "Mig23";
    function AttachDangerEvent(){
    	for (m=1; m<=4; m++) {
    		attachMovie("DangerEvent"+[m],"DangerEvent"+[m]+"MC",10);
    	}
    }
    timer = setInterval(pause, random(5000));
    if (timer > 0 && timer < 2000){
    	AttachDangerEvent;
    	} else if (timer > 2000 && timer < 3000){
    		AttachDangerEvent;
    	} else if (timer > 3000 && timer < 5000){
    		AttachDangerEvent;
    }
    Moving at the speed of Flash

  2. #2
    Senior Member
    Join Date
    Feb 2001
    Location
    On the fifth floor.
    Posts
    1,202
    Try this code:
    FIRST FRAME
    ---------------------
    Code:
    clearInterval(timer);
    DangerEvent = new Array();
    DangerEvent[0] = "BLMissile";
    DangerEvent[1] = "BRMissile";
    DangerEvent[2] = "TRMissile";
    DangerEvent[3] = "Mig23";
    function AttachDangerEvent(){
    	m = DangerEvent.length;
    	r = random(m)
    	this.attachMovie(DangerEvent[r],"DangerEvent"+r+"MC",10);
    //	_root["DangerEvent"+r+"MC"]._x = 200;
    //	_root["DangerEvent"+r+"MC"]._y = 100;
    }
    SECOND FRAME
    Code:
    stop();
    timer = setInterval(function(){play()}, random(3000)+2000);
    AttachDangerEvent();

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