Scoping Issues – AS2 Class, Context Menu


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: , , , , , , ,

Advertisements

2 thoughts on “Scoping Issues – AS2 Class, Context Menu

  1. 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
    }
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s