I have been working on flash and happened to use Context Menu, and ran in to scoping issues in a AS2 Class. I hope some flash Guru will look at the code and help me fix it up.
Let me list the code where I have changed the class name and Listing the necessary lines for understanding the Code
class test{var testarr:Array;function test(){ testArr= new Array("l1","l2");}public function deleteme() { var lineMC:MovieClip = _root.attachMovie("test","test",100); var myContextMenu = new ContextMenu (); myContextMenu.hideBuiltInItems (); var del = new ContextMenuItem ("Delete Link", contextMenu); myContextMenu.customItems.push (del); lineMC.menu = myContextMenu;} public function get returnArray():Array{ return test_arr }public function contextMenu (obj:Object,menu:ContextMenu):Void { // here I want to access the returnArray function trace(returnArray) // I get the answer undefined any answers please let me know }}
Hope to see some anwsers, In simple words I looking for AS2 Class
Technorati Tags: Actionscript, Scoping issues, context Menu, Menu, Flash, AS2, Actionscript AS2, Class
May 24, 2006 at 5:40 pm |
The rightly use of Event delegate solved my problem, Thanks a ton to Ashok, my buddy
May 24, 2006 at 8:42 pm |
here is the sample code which works
import mx.utils.Delegate;
class test
{
public var test_arr:Array = new Array();
function test()
{
}
public function deleteme()
{
var lineMC:MovieClip = _root.attachMovie(”test”, “test”, 100);
var myContextMenu = new ContextMenu();
myContextMenu.hideBuiltInItems();
var del = new ContextMenuItem(”Delete Link”,Delegate.create(this,contextMenu));
myContextMenu.customItems.push(del);
//myContextMenu.onSelect = menuHandler;
lineMC.menu = myContextMenu;
}
public function get returnArray():Array
{
return ['a'];//test_arr;
}
public function contextMenu(obj:Object, menu:ContextMenu):Void
{
// here I want to access the returnArray function
trace(this.returnArray);
// I get the answer undefined any answers please let me know
}
}