-
Hi
I want to to delete a sepcified item out of my array:
Here is the code:
Code:
for (/checkbox1/:i =0; /checkbox1/:i<= /:Songlist.length; /checkbox1/:i++) {
if (eval(/:Songlist[/checkbox1/:i] ) =/:id1) {
/:Songlist.splice(/checkbox1/:i,1);
}
}
Now if the array songlist has the elements 1,2,3,4,5
Then if i run this script with /:id1 = 3
This is what happens
Songlist array becomes: 2,4
i want it to be: 1,2,4,5 (with the 3 being removed)
what have i done wrong?
Thanks
Ash
-
Hi ashwinv...when I tried to run your script I got a warning that it was making the Flash Player run slow....and I'm not real sure why....except a couple of things... you're using the wrong operator in this line, I think it should be...
if (eval(/:Songlist[/checkbox1/:i] ) == /:id1) {
...and I'm not real certain why you would need "eval"
but anyway I re-wrote it like this and it works...
Code:
Songlist = new Array(1, 2, 3, 4, 5);
id1 = 3;
for (i=0; i<=Songlist.length; i++) {
if (i == id1) {
Songlist.splice(i-1, 1);
}
}
trace (Songlist);
...and keep in mind, Flash counts the first object in an Array as "0"...which is why I used "i-1" as the startIndex in the "splice"
Hope this helps...
-pigghost-
EDIT: After looking at it further, a better way would be like this (similar to what you had, but without the "eval") and it works...
Code:
for (j=0; j<=Songlist.length; j++) {
if (Songlist[j] == id1) {
Songlist.splice(j, 1);
}
}
I had to change it to "j" because "i" in square brackets is read as italics on the board....
Hope this points you in the right direction.......
-pg-
[/CODE]
[Edited by pigghost on 12-08-2001 at 03:08 PM]
-
Hi
it was the == that was the solution....however i still have a small problem. I have this checkbox with this script running many times, so it has many relative variable calls.
This is what requires the eval() statements.
This i what it looks like
Code:
on (release) {
for (eval("/main/bottom/playlist/playlist/checkbox" add this.number add "/:i ")=0; eval("/main/bottom/playlist/playlist/checkbox" add this.number add "/:i") <= /main/bottom/playlist/playlist/:Songlist.length; eval("/main/bottom/playlist/playlist/checkbox" add this.number add "/:i ")++) {
if (eval(/main/bottom/playlist/playlist/:Songlist[eval("/main/bottom/playlist/playlist/checkbox" add this.number add "/:i ")]) == eval("/main/bottom/playlist/playlist/:id" add this.number)) {
/main/bottom/playlist/playlist/:Songlist.splice(eval("/main/bottom/playlist/playlist/checkbox" add this.number add "/:i "),1);
}
}
gotoAndStop (2);
}
This works fine without the "this.number"
What is wrong with this?
Any ideas how to solve it.
Please give me you verdict
Ash
[Edited by ashwinv on 12-08-2001 at 03:40 PM]
-
Woah! Your mixing of Flash4 and Flash5 syntax is giving me a headache....lol...just kidding!
Okay, I'm assuming you have several checkboxes and they're all running this code?? Looks like you need to get this off your buttons and into a function that you just pass a parameter to...
...and the keyword "this" will not work on a button I don't think...because it's generally used to reference a movieClip in an "onClipEvent" or you could use it in a function that is going to be called with an "onClipEvent"
..of course, I'd really have to know a little more what you're trying to do and see the .fla to give you anymore than guesses......
Sorry I'm not more help...
-pigghost-
-
Ash...I sent you an .fla......
-pigghost-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|