Array() VS Array()

What is the fundamental difference between the two arrays when dealt with the functions pointer2array() and duplicateArray()

 

   1:  var original_arr:Array = new Array()
   2:  var some_arr:Array = new Array("one","two","three")
   3:   
   4:  function pointer2array(){
   5:      original_arr = some_arr
   6:  }
   7:  function duplicateArray(){
   8:     for(var k:Number=0;k
   9:        original_arr.push(some_arr[k]);
  10:    }
  11:  }
first using the duplicateArray()
 

   1:  trace(original_arr.toString() + newline);
   2:  duplicateArray();
   3:  some_arr.push("four")
   4:  trace("some_arr="+ some_arr.toString() + newline)
   5:  trace("original_arr="+original_arr.toString() + newline)

Now Publish the flash swf to have the below result

result:

one,two,three

some_arr=one,two,three,four

original_arr=one,two,three

Now try using the pointer2array()

      1: trace(original_arr.toString() + newline);

   2:  pointer2array();
   3:  some_arr.push("four")
   4:  trace("some_arr="+ some_arr.toString() + newline)
   5:  trace("original_arr="+original_arr.toString() + newline)
After you publish the flash swf you will be shocked to see the result
result:

one,two,three

some_arr=one,two,three,four

original_arr=one,two,three,four

The difference is that original_arr is a reference to some_arr, so be careful.

Well I am not a hard core programmer, I have been programming for days and some times you tend to forget the concepts. Just a reminder

The above code holds good for JavaScript too.

 

Flash 8 Context Menu Bug – no work around

Flash 8 has an excellent example of creating a context Menu, but the issue I faced was when I used actionscript to dynamically attached clips on stage and on right click I want to activate the Context Menu.

It seems like there is Bug with context menu in flash 8 player, one example from a user I found on Kaourantin page which would actually crash the browser, player or even flash 8 IDE, so I turned around to check for any work around’s, found one on Abdul Quabiz site (link to the context menu workaround page), well, his workaround also was not of big help to me.

No one from the flash team seems to say when the bug will be fixed or will there be any issue tracking page for the flash users to check whether the same has been fixed so that we could update our software. BTW I had updated my flash 8, still I am unable to make this functionality working on my product.

hope some day there will fix to this Context Menu.

Kindly Note: I am unable to attach my flash source file as I don’t have public domain where I can upload files for all you to download and test the files. If any one has a workaround please let me know.

Easy way to pop() your Array List

I have been working on Arrays in Flash and had to repopulate the array with the new set of values. I have been using array.pop() method to empty the list with a for loop, currently I found an easier way

 

   1:  var a_arr:Array = new Array("one","two","three");
   2:  var b_arr:Array = new Array("one","two","three");
   3:   
   4:  function clearArray(arr:Array):Void
   5:  {
   6:      arr.splice(0,arr.length);
// splice removes elements from index,count
   7:  }
   8:  function oldarraypopmethod(arr:Array):Void
   9:  {
  10:     for(var i:Number=0;i
  11:     arr.pop();
  12:  }
  13:  // new method 
  14:  trace("before a_arr"+ a_arr.toString());
  15:  clearArray(a_arr);
  16:  trace("after a_arr"+ a_arr.toString());
  17:  trace("before b_arr"+ b_arr.toString());
  18:  oldarraypopmethod(b_arr);
  19:  trace("after b_arr"+ b_arr.toString());
I find the new Method doesn't take too much line. 
The above line of code can be applied to JavaScript too.