Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Flash Actionscript / April 2005



Tip: Looking for answers? Try searching our database.

Array duplication?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
davepla - 29 Apr 2005 22:21 GMT
Hi:

how can I duplicate an existing array? If I do:

bufferTmp = buffer;

being buffer an array, bufferTmp contains a reference to the same array not a copy

TIA,

David P.
Boonana - 29 Apr 2005 22:51 GMT
did you try:

bufferTmp = new Array();
bufferTmp = buffer;
davepla - 29 Apr 2005 23:00 GMT
Yes, I tried declaring bufferTmp as an array but it keeps referencing buffer array
Jeckyl - 30 Apr 2005 02:42 GMT
What the does is create a new array, and assign a reference to it to
bufferTmp

Then it removes the reference to the new array (making it disappear) and
replaces it with a reference to bufferTmp .. do bufferTmp and buffer both
refer to the same array.
Signature

Jeckyl

> did you try:
>
> bufferTmp = new Array();
> bufferTmp = buffer;
Rothrock - 29 Apr 2005 23:59 GMT
Yup that is how it works in Flash. What you want to do is create a new blank
array and then step through and duplicate each element in the array.

//some arrray that already exists called myFirstArray
mySecondArray=new Array();
for(i in myFirstArray){
mySecondArray=myFirstArray;
}

At least I think it something like that. I didn't actually test it. Let me
know if that doesn't work for you.
NSurveyor - 30 Apr 2005 00:24 GMT
You cannot duplicate an array using bufferTmp = buffer; Bot bufferTmp and
buffer will still reference (point) to the exact same array. Strings and
Numbers can be duplicated in this way but I believe all the rest will just
"point" as they are not primitive. I would just use concat to duplicate it.
Something like:

bufferTmp = new Array();
bufferTmp = bufferTmp.concat(buffer);
kglad - 30 Apr 2005 01:43 GMT
or

buffertemp=buffer.concat();
davepla - 30 Apr 2005 15:12 GMT
Yes, you're right. It's the way many languages treat objects when you assign
them to a var/object, creating a reference to it instead a copy. I was looking
for something like duplicate function in Lingo:

bufferTmp = buffer.duplicate()

Finally I found that's what slice method do if you don't pass any parameter:

bufferTmp = buffer.slice()

Thanks to everybody for your help,

David P.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.