Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 1.0 (and below)

Reply
 
Thread Tools Rate Thread Display Modes
Old 09-29-2001, 01:11 PM   #1
pinkaboo
power to the pinK
 
pinkaboo's Avatar
 
Join Date: Jul 2001
Location: Atlanta Atlanta ATLANTA!
Posts: 1,527
Send a message via ICQ to pinkaboo
Default remove item from array

Please, could someone tell me how to remove an item from an array please?

for example:

remove = "";
MyArray = [1, 2, 3, 4, 5, 6];


if "remove"= 4 I want :
MyArray = [1, 2, 3, 5, 6];

(or to create a new array?)

How can I do this?

Thanks in advance,

K
pinkaboo is offline   Reply With Quote
Old 09-29-2001, 11:15 PM   #2
red penguin
[^\d\D]
 
red penguin's Avatar
 
Join Date: Jun 2001
Location: Brooklyn, NY
Posts: 3,254
Default

splice() is what you need, baby...

...It can add or subtract elements from an array. In your example...
Code:
MyArray.splice(3, 1);
This will effectively remove the 4th element from the array. Remember that array elements begin with "0"...
yeah?
__________________

komielan.com
red penguin is offline   Reply With Quote
Old 09-30-2001, 04:29 PM   #3
pinkaboo
power to the pinK
 
pinkaboo's Avatar
 
Join Date: Jul 2001
Location: Atlanta Atlanta ATLANTA!
Posts: 1,527
Send a message via ICQ to pinkaboo
Wink

Thanks very much, I'll go and try that now.

Although I have a query - if the first number removes the corresponding element from an array, what does the second number do?

cheers

K
pinkaboo is offline   Reply With Quote
Old 09-30-2001, 06:02 PM   #4
tg
done
 
Join Date: Jun 2001
Location: portland, or
Posts: 8,106
Default

i believe the first number tells flash where to start pulling elements out of the array, the second number tells flash how many elements to pull out of the array.

i'm not sure exactly, so check help in flash
__________________
tg
---
what the hell was i thinking?
tg is offline   Reply With Quote
Old 09-30-2001, 08:17 PM   #5
red penguin
[^\d\D]
 
red penguin's Avatar
 
Join Date: Jun 2001
Location: Brooklyn, NY
Posts: 3,254
Default

Right-o! The second argument tells the interpreter how many elements to get rid of! (referred to as the deleteCount)
If you don't give deleteCount, it'll remove the remaining elements...
Code:
var foo = new Array("1", "2", "3", "4", "5", "6");
foo.splice(4);
//foo is now 1, 2, 3, 4
foo.splice(1,1);
//foo is now 1, 3, 4
foo.splice(1, 0, "blah")
//used splice to insert "blah" into foo.
//foo is now 1, blah, 3, 4
//Note the use of zero for the deleteCount
Cool, eh?
__________________

komielan.com
red penguin is offline   Reply With Quote
Old 10-01-2001, 02:45 PM   #6
pinkaboo
power to the pinK
 
pinkaboo's Avatar
 
Join Date: Jul 2001
Location: Atlanta Atlanta ATLANTA!
Posts: 1,527
Send a message via ICQ to pinkaboo
Default

awesome

thank you very much, both of you

I think I actually understand splice now, well, a bit clearer now anyway! I'd been wading through the tutorials/function library in dispair because although people had been fantastic enough to submit code I didn't have a clue how to interpret it to make it useful. Feel like I'm getting somewhere now.

cheers

K
pinkaboo is offline   Reply With Quote
Old 10-02-2001, 01:29 AM   #7
Jesse
ActionScript.org Founder
 
Jesse's Avatar
 
Join Date: Nov 2000
Location: New York
Posts: 8,736
Default

Remember that like most of the prototypes which ship with Flash are very innefficient. People have ade their own Splice functions and posted them about the place. Apparently they're 40% faster if you want to look around...
__________________
Cheers

Jesse Stratford
ActionScript.org Cofounder

Please don't email or PM me Flash questions, that's what the Forums are for!

Please don't rely on me reading my PMs either. Email me about important stuff.
Jesse is offline   Reply With Quote
Old 10-02-2001, 04:17 AM   #8
tg
done
 
Join Date: Jun 2001
Location: portland, or
Posts: 8,106
Default

prototype is a great place to find some wonderful code/prototypes. the folks there have it set up so users keep the database updated, and can comment on other code available to everyone.

the bad news is they are down right now, but hopefully will be back soon.

here is the dress http://www.layer51.com/proto/
__________________
tg
---
what the hell was i thinking?
tg is offline   Reply With Quote
Old 10-02-2001, 10:16 AM   #9
red penguin
[^\d\D]
 
red penguin's Avatar
 
Join Date: Jun 2001
Location: Brooklyn, NY
Posts: 3,254
Default

Thanks for the info tg! Haven't checked it out yet but look forward to it!
__________________

komielan.com
red penguin is offline   Reply With Quote
Old 10-15-2001, 08:27 PM   #10
pinkaboo
power to the pinK
 
pinkaboo's Avatar
 
Join Date: Jul 2001
Location: Atlanta Atlanta ATLANTA!
Posts: 1,527
Send a message via ICQ to pinkaboo
Default

TG - fantastic, that link you posted is now working again (hoorah) and I've just checked it out. Looks like a great site, thanks very much for the tip.

cheers

K
pinkaboo 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove item in Array output marxseven ActionScript 1.0 (and below) 8 12-17-2006 10:59 PM
problem creating mc instance names inside a function jasonyen ActionScript 2.0 10 12-08-2004 12:01 AM
removing a specified item from an array? Clox ActionScript 2.0 2 11-16-2004 05:11 AM
trouble with variable getting lost whoo Simple Stuff (Newbies) 2 08-07-2004 05:52 PM
Deleting a specific item of an array - works 100% ckey ActionScript 1.0 (and below) 3 02-07-2003 08:18 PM


All times are GMT. The time now is 03:53 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.