Reputation: 2693
I call the function below from the context menu and graphics get cleared. If the call comes from within another function it don't. Why it's not working than?
function removeFrame(e:Event=null):void{
holder.graphics.clear();
}
function cleanIt(e:Event=null):void{
removeFrame()
}
// NOT working by calling it like this:
cleanIt()
// It's Working if I call the function directly from the right-click menu:
menuitem1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,cleanIt);
Thanks. Uli
Upvotes: 0
Views: 6376
Reputation: 35684
can you show more code, how is the function called? It looks like it's an event listener function, which can change the scope of what this
means (ie. this.holder
). You could make the function class level: function removeFrame(e:Event=null):void{
and have it inside the class. Though it's hard to tell exactly without seeing more code.
I've tried in an fla file
import flash.display.Sprite;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
var holder:Sprite = new Sprite();
holder.graphics.beginFill(0x443311,1);
holder.graphics.drawCircle(10,10,300);
addChild(holder);
var cm:ContextMenu = new ContextMenu();
var menuitem1:ContextMenuItem = new ContextMenuItem("HAHA")
cm.customItems.push(menuitem1);
contextMenu = cm;
function removeFrame(e:Event=null):void{
holder.graphics.clear();
}
function cleanIt(e:Event=null):void{
removeFrame()
}
cleanIt();
menuitem1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,cleanIt);
and cleanIt
works for both, need more info or code to know what's going on.
Upvotes: 1