-
deleting an array?
everyone, i'm still working on my new little web site, improving a lot the code (since the old version i mean); i'm now focusing on the code for the dialog boxes, more flexible and a lot less cpu intensive ^^
but, i was wondering: is there a way to delete an array?
well, i don't mean delete the content of an array, like
but effectively erasing the array itself completely...
thanks for your help, and i hope it will fix a "bug" i'm currently having.
-
To make it non existant?
What about trying
something = your array
then to erase it
something = null
-
-
so simple...
thanks senoclouar, my favorite funny overweight ^^
in fact it didn't solved my problem (the array is effectively deleted though), i guess i'll take another way.
anyway, that problem seems strange; here it is:
i have a MC with that array:
Code:
onClipEvent (load) {
action = new Array();
action = ["speak", "announce2_in", 1, "announce1_in", 2, "announce1_out"];
}
^ that array is used for special actions. for example, "speak" means that a windowed text box will appear, and the main character will be "frozen" until the end of the process.
when the character hits that MC and push action key, he copies that array:
Code:
// action array is copied
interaction = new Array();
interaction = _parent.whatever.action;
then i use a trace action, the array is correctly copied into my character's MC.
after that, i tell
Code:
interaction.shift()
to remove the first array element. "annouce2_in" means that the windowed text box called "annouce2_in" will open. "1" is the text that will appear in the window, using an array that stores all in game texts.
all the process works very well until the end (the windowed text box is closed, your character is playable again).
but when i try to replay that sequence (to re-read something written into the door for example), nothing more appears.
> i discovered by using the trace action that the original array (the one above i copied) is also "shifted"...? i don't know why, i probably did something wrong.
anyway, i'll try another way. thanks for your help though.
-
1) action = new Array(); is an unnecessary line, as is interaction = new Array(); If you are going to be assigning the variables to be arrays using = (some array) you dont have to first declare the array to be an array. You only really need that if you want to use array operations on it like concat before you actually assign it to anything. Its not really a big deal and its not hurting anything, but it can save you a lot of typing in the long run. Though, some people like to include that line so they can search for an instance of "new Array()" with the code and find out where the array is first initialized.... ANYWHO
2) the real problem is that arrays are referenced as pointers not direct values. Since arrays are a contiguous stretch of saved variables in memory, flash has no real way of knowing just how big the array is going to be and how much space it needs to take up in memory. So, when created they are set aside some space in memory and remembered by flash with a "reference" to that point in memory using your variable (ie. myArray = [] <-- myArray is a reference to the point in memory where your actuall array values begin). Now the thing with references is that, well they're like shortcuts or mac aliases. If you copy a shortcut to flash.exe thats on your desktop and put it in the "my documents" folder, you didnt actually copy the Flash.exe application file, just the shortcut. Both shortcuts still point to the same flash. Thats what you did, you copied that shortcut, gave it a new name and then opened it. It opened flash, you devilishly changed the preferences to display all actionscript in Comic Sans and then closed it quickly without letting anyone see you (shweew). Now you go back to the original shortcut and try to open what you think is a lucida console displaying flash application, but instead its showing comic sans. You used a different shortcut, or reference, but you still affected the same preferences or saved variables/memory etc. Well I think Im beating a dead horse here, but atleast you know whats going on (I hope?)
... prevent this use
newArray = oldArray.slice()
and that makes a copy since slice returns a copy without affecting the original array.
BUT BE CAUTIOUS! if you have an array (or an object, object variables are also references) WITHIN that array and you just use newArray = oldArray.slice() then those internal arrays arent copied, just they're reference variables. So technically youd have to go throuh each one of those and slice them as well.
Im pretty sure www.layer51.com/proto has a function that goes through and makes a copy for all instances of an object or array within whatever one you want to copy... but for this situation I dont think you have to worry about that
.................
so the short answer is, use
interaction = _parent.whatever.action.slice();
-
i see.
thanks for taking your time senocular, and thanks to be the second, token3 ^^.
well, i just learned something new about arrays today, thanks to you.
anyway, i just changed a little bit the code in order to make the process work without shifting any array (i just added a new variable, nothing more)... and now it works flawlessly, in a really more flexible and very less cpu/time consuming way than my old rocky game.
your explanation is very interesting though, thanks again ^^