A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: goto a frame when an array is empty

  1. #1
    Senior Member
    Join Date
    May 2006
    Posts
    119

    goto a frame when an array is empty

    Im wondering, I have this script courtesy of MD004 (thanks again)
    and Im wondering how I can make it goto the frame labeled "congradulations" when the array is empty. this is what I have.

    Code:
    function arrayRandomizer(a, b) {
    	var value = (random(2)==0) ? -1 : 1;
    	return value;
    }
    
    frames = [2,3,4,5,6,7,8,9,10,11,12,13]; // this is the array of frames
    frames.sort(arrayRandomizer);
    
    
    currentFrameCount=0;
    function nextFrame() {
    	gotoAndStop(  frames[currentFrameCount]  );
    	currentFrameCount++;
    }
    I tried just putting a

    Code:
    if( frames == "" ){ 
     _root.gotoAndPlay("congradulations");
    }
    but it doesn't goto the frame
    any suggestions?

    thanks in advance

    Mark
    Last edited by MarkSensei; 06-21-2006 at 09:42 AM.

  2. #2
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    You're nearly there with it, just remember to use trace() whenever you can, it'll help with debugging so much.

    Give this a try mate:
    Code:
    function nextFrame() {
            if(++currentFrameCount<frames.length){
      	      gotoAndStop(frames[currentFrameCount]);
            } else {
                  _root.gotoAndPlay("congradulations");
            }
    }
    Squize.

  3. #3
    Senior Member
    Join Date
    Apr 2005
    Posts
    467
    What about a simple

    Code:
    if (frames.length == 0) {
    _root.gotoAndPlay("congradulations");
    }
    Hope nobody knows I am still on Flash 5
    ______________________________________
    All artists are prepared to suffer for their work
    but why are so few prepared to learn to draw?(Banksy)

  4. #4
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Because the frames array isn't being spliced, it's just the contents being randomised, so you have to use the array offset and compare that to the length, rather than the length property itself ( Which will never change ).

    Squize.

  5. #5
    Senior Member
    Join Date
    May 2006
    Posts
    119
    Thanks so much! I will give that a go!
    Man I can't wait until I can just look at a piece of code and understand it inside and out like alot of the folk on this forum.
    I was under the impression that the piece of code I was working with was splicing the array...

    Thanks again!

    Mark

  6. #6
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793
    trace, trace, trace!
    And watch your spelling. ;-)

  7. #7
    Senior Member
    Join Date
    May 2006
    Posts
    119
    I've never really taken to "trace" yet, maybe I should look into it more. Thanks

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