newProxyCallback()

Usage

spriteObjRef.newProxyCallback(#handlerName {scriptObject}) 

Description

This method creates an ActionScript function object, which can be passed to ActionScript’s addEventListener() method.

Parameters

handlerName Required. This parameter specifies the Lingo/Javascript handler that should be called when the callback is triggered from the ActionScript 3 script of the Flash sprite.

scriptObject Optional. This parameter returns a Lingo/Javascript object that can be used to pass in-place an ActionScript function object to get a callback in Adobe Director.

Example

The following example creates a callback and passes it to the addEventListener() method and then handles the event in Adobe Director:

-- Lingo syntax 
on testAS3ToLingoCallback  
     spr = sprite("AS3Swf")  
     lcbk  = spr.newProxyCallback(#mouseUpLingoHandler) 
    -- get a reference to the AS3 MouseEvent class 
    mouseUpEvt = spr.getVariable("flash.events.MouseEvent", false) 
    -- get a reference  to a button/movieclip object present inside SWF.. 
    -- Here, the "root1" is assumed to be the child of "stage" object of the SWF. 
    flbtn = spr.getVariable("root1", false) 
    –- Pass the lingo callback instead of a AS3 Function object 
    flbtn.addEventListener(mouseUpEvt.MOUSE_UP, lcbk) 
end 
on mouseUpLingoHandler evt 
    put "Got the mouseUp callback from Flash As3!!" 
    put "You clicked on " & evt.target.name 
end 
// JavaScript syntax 
function testAS3ToJSCallback() 
{ 
    spr = sprite("AS3Swf"); 
    lcbk = spr.newProxyCallback(symbol("mouseUpJSHandler")); 
    // Get a reference to the AS3 MouseEvent class 
    mouseUpEvt = spr.getVariable("flash.events.MouseEvent", false); 
    // Get a reference to a button object present inside the SWF. 
    // Here, the "root1" is assumed to be the child of "stage" object of the SWF. 
    flbtn = spr.getVariable("root1", false); 
    // Pass the lingo callback instead of a AS3 Function object 
    flbtn.addEventListener(mouseUpEvt.MOUSE_UP, lcbk); 
} 
function mouseUpJSHandler(evt) 
{ 
    trace("Got the mouseUp callback from Flash As3!!"); 
    trace("You clicked on " + evt.target.name); 
}