Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-28-2005, 04:34 AM   #1
lisaad
Registered User
 
lisaad's Avatar
 
Join Date: Nov 2004
Location: Brooklyn
Posts: 10
Default problem removing item from an array

I'm having trouble removing an element from an array. my array is filename, and i want to randomly select one item, then remove it so it isn't selected again.

here's my code:

ActionScript Code:
selectRandom = function(){     filename =  ["p1_1.swf", "p1_2.swf", "p1_3.swf", "p1_4.swf", "p1_5.swf", "p1_6.swf"];     path =  "http://a.parsons.edu/~lisa/spring05/interactivity/final/swfs/";     i =  filename.length;        k =  Math.floor(Math.random()*i);        randomFile = filename[k];     filename.splice(k,1);        return(randomFile);         return(path);       }

is there something I'm missing?
lisaad is offline   Reply With Quote
Old 04-28-2005, 06:06 AM   #2
pcarini
Shameless Audiophile
 
pcarini's Avatar
 
Join Date: Aug 2004
Posts: 129
Default

The problem is that everytime you call selectRandom() you're assigning filename all of your clips again. You need to move the lines filename = and path = somewhere outside of your function. This might be more of what you're looking for:

ActionScript Code:
filename =  ["p1_1.swf", "p1_2.swf", "p1_3.swf", "p1_4.swf", "p1_5.swf", "p1_6.swf"];     path =  "http://a.parsons.edu/~lisa/spring05/interactivity/final/swfs/";         selectRandom = function(){             k = random(filename.length-1);             randomFile = filename[k];             filename.splice(k,1);             return(randomFile);     }

Then you could use it somewhere like:

ActionScript Code:
filePath = path + selectRandom();

Hope it helps some,
-C

Last edited by pcarini; 04-28-2005 at 06:09 AM.
pcarini is offline   Reply With Quote
Old 04-29-2005, 01:22 AM   #3
lisaad
Registered User
 
lisaad's Avatar
 
Join Date: Nov 2004
Location: Brooklyn
Posts: 10
Default

*sigh* i should have caught that. thanks so much!!
lisaad is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:54 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.