[Laszlo-dev] swf9 ExternalInterface.addCallback

Sarah Allen sarah at ultrasaurus.com
Sun Jun 21 09:43:55 PDT 2009


Thanks for the pointers, Max.  I start in on it, but I have a few  
questions

It looks like I should just copy the code (snippet below) into the  
applet_tag defeinition, parameterizing "lzapp" and the other params.
* How do I pass in vars?
* Does it use swfobject underneath or have its own auto-install Flash  
stuff in it?
* swfobject has a nice feature where you name a div where you want it  
to go and if there is no Flash it will display whatever is in that  
div... is there anything like that built in? If not, I'll add that to  
my list.

<script type="text/javascript" src="/trunk/lps/includes/embed- 
compressed.js"></script>
<script type="text/javascript">
                   lz.embed.swf({url: 'copy-of-hello.lzx?lzt=swf',  
allowfullscreen: 'false', bgcolor: '#ffffff', width: '100%', height:  
'100%', id: 'lzapp', accessible: 'false'});
</script>
<noscript>
        Please enable JavaScript in order to use this application.
  </noscript>


On Jun 21, 2009, at 8:58 AM, Max Carlson wrote:

> I'm a little busy working on my talk now, but I should have more  
> time in a few days.  I can help you if you get stuck, but in the  
> mean time you may want to check out the templates here:
> http://svn.openlaszlo.org/openlaszlo/trunk/WEB-INF/lps/templates/html-response.xslt
>
> You can also look at the generated HTML for your app with lzt=html.
>
> Did you get the automatic dataset/model synchronization working  
> again? If so, very cool!
>
> Sarah Allen wrote:
>> Any interest in collaborating on how to add that to  
>> openlaszlo_plugin for rails?  or give me a hint as to where to  
>> start? (oddly I know next to nothing about the lz.embed code and  
>> how to integrate it onto a page of my own... must be in the dguide  
>> somewhere, I suppose)
>> I got the tests working in the lastest rails (and older 2.x should  
>> work too) and added a bunch of tests for the applet and swfobject  
>> tags. Oliver hasn't pulled yet, so the latest is at:
>>     http://github.com/ultrasaurus/openlaszlo_plugin/tree/master
>> On Jun 21, 2009, at 8:26 AM, Max Carlson wrote:
>>> You'd use:
>>>
>>> value = lz.embed.lzapp.callMethod('canvas.anyMethod(...)')
>>>
>>> > Also, do I need all the lz embed stuff to do this?  I was just  
>>> using
>>> > swfobject_tag in rails...  and then I would just call the method  
>>> on the
>>> > object in javascript.
>>>
>>> Yes, you will need the lz.embed stuff.  It has lots of other  
>>> benefits, like history and mousewheel support.
>>>
>>> Sarah Allen wrote:
>>>> Can I just declare a method on the canvas and call it with:
>>>> value =  
>>>> lz.embed.lzapp.callMethod('globalreference.canvas.anyMethod(...)')
>>>> Also, do I need all the lz embed stuff to do this?  I was just  
>>>> using swfobject_tag in rails...  and then I would just call the  
>>>> method on the object in javascript.
>>>> Sarah
>>>> On Jun 20, 2009, at 12:59 PM, Max Carlson wrote:
>>>>> It just means you need a top-level instance with an ID.  You can  
>>>>> do this in a script if you want to...
>>>>>
>>>>> Sarah Allen wrote:
>>>>>> What does this mean:  "You can call any available method in the  
>>>>>> application as long as 'globalreference' can be found in the  
>>>>>> global scope." ?
>>>>>> Do I need to define "globalreference" in a script tag?
>>>>>> Thanks,
>>>>>> Sarah
>>>>>> On Jun 19, 2009, at 1:20 PM, Max Carlson wrote:
>>>>>>> Yes!  See the docs for any app with lzt=deployment, e.g.:
>>>>>>> http://labs.openlaszlo.org/trunk-nightly/my-apps/copy-of-hello.lzx?lzt=deployment
>>>>>>>
>>>>>>> To call a method in an application, use:
>>>>>>>
>>>>>>> value =  
>>>>>>> lz 
>>>>>>> .embed 
>>>>>>> .lzapp.callMethod('globalreference.reference.anyMethod(...)')
>>>>>>>
>>>>>>> passing a string representation of the method and any  
>>>>>>> arguments you wish to pass. You can call any available method  
>>>>>>> in the application as long as 'globalreference' can be found  
>>>>>>> in the global scope.
>>>>>>>
>>>>>>> To call a method in all applications on the page, use:
>>>>>>>
>>>>>>> lz.embed.callMethod('globalreference.reference.anyMethod(...)')
>>>>>>>
>>>>>>> Sarah Allen wrote:
>>>>>>>> So, is there any native-LZX way to do this?  or is the Flash  
>>>>>>>> API the best I can do for now?
>>>>>>>> Thanks!
>>>>>>>> Sarah
>>>>>>>> On Jun 12, 2009, at 10:12 AM, Henry Minsky wrote:
>>>>>>>>> You're looking at out of date docs, the new docs say it has  
>>>>>>>>> two args.
>>>>>>>>>
>>>>>>>>> See the docs at http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/
>>>>>>>>>
>>>>>>>>> addCallback    ()    method
>>>>>>>>>
>>>>>>>>> | public static function addCallback(functionName:String <http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html 
>>>>>>>>> >, closure:Function <http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Function.html 
>>>>>>>>> >):void <http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/specialTypes.html#void 
>>>>>>>>> >|
>>>>>>>>> * Language Version : *    ActionScript 3.0
>>>>>>>>>
>>>>>>>>> * Runtime Versions : *    AIR 1.0, Flash Player 9
>>>>>>>>>
>>>>>>>>> Registers an ActionScript method as callable from the  
>>>>>>>>> container. After a successful invocation of |addCallBack()|,  
>>>>>>>>> the registered function in Flash Player can be called by  
>>>>>>>>> JavaScript or ActiveX code in the container.
>>>>>>>>>
>>>>>>>>> *Note:* For /local/ content running in a browser, calls to  
>>>>>>>>> the |ExternalInterface.addCallback()| method work only if  
>>>>>>>>> the SWF file and the containing web page are in the local- 
>>>>>>>>> trusted security sandbox. For more information, see the  
>>>>>>>>> following:
>>>>>>>>>
>>>>>>>>> * The security chapter
>>>>>>>>>   <http://www.adobe.com/go/flashCS3_progAS3_security> in the
>>>>>>>>>   /Programming ActionScript 3.0/ book and the latest  
>>>>>>>>> comments on
>>>>>>>>>   LiveDocs
>>>>>>>>> * The Flash Player 9 Security white paper
>>>>>>>>>   <http://www.adobe.com/go/fp9_0_security>
>>>>>>>>>
>>>>>>>>> Parameters
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>  |functionName:String <http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html 
>>>>>>>>> >| — The name by which the container can invoke the function.
>>>>>>>>>
>>>>>>>>>  |closure:Function <http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Function.html 
>>>>>>>>> >| — The function closure to invoke. This could be a free- 
>>>>>>>>> standing function, or it could be a method closure  
>>>>>>>>> referencing a method of an object instance. By passing a  
>>>>>>>>> method closure, you can direct the callback at a method of a  
>>>>>>>>> particular object instance.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Throws
>>>>>>>>>
>>>>>>>>>  |Error <http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Error.html 
>>>>>>>>> > | — The container does not support incoming calls.  
>>>>>>>>> Incoming calls are supported only in Internet Explorer for  
>>>>>>>>> Windows and browsers that use the NPRuntime API such as  
>>>>>>>>> Mozilla 1.7.5 and later or Firefox 1.0 and later.
>>>>>>>>>
>>>>>>>>>  |SecurityError <http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/SecurityError.html 
>>>>>>>>> > | — A callback with the specified name has already been  
>>>>>>>>> added by ActionScript in a sandbox to which you do not have  
>>>>>>>>> access; you cannot overwrite that callback. To work around  
>>>>>>>>> this problem, rewrite the ActionScript that originally  
>>>>>>>>> called the |addCallback()| method so that it also calls the | 
>>>>>>>>> Security.allowDomain()| method.
>>>>>>>>>
>>>>>>>>>  |SecurityError <http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/SecurityError.html 
>>>>>>>>> > | — The containing environment belongs to a security  
>>>>>>>>> sandbox to which the calling code does not have access. To  
>>>>>>>>> fix this problem, follow these steps:
>>>>>>>>>
>>>>>>>>> 1. In the |object| tag for the SWF file in the containing HTML
>>>>>>>>>   page, set the following parameter:
>>>>>>>>>
>>>>>>>>>   |<param name="allowScriptAccess" value="always" />|
>>>>>>>>>
>>>>>>>>> 2. In the SWF file, add the following ActionScript:
>>>>>>>>>
>>>>>>>>>   |flash.system.Security.allowDomain(/sourceDomain/)|
>>>>>>>>>
>>>>>>>>> See also
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Fri, Jun 12, 2009 at 12:51 PM, Sarah Allen <sarah at ultrasaurus.com 
>>>>>>>>>  <mailto:sarah at ultrasaurus.com>> wrote:
>>>>>>>>>
>>>>>>>>> I'm seeing a weird compiler error in trunk... might be recent
>>>>>>>>> regression (it is possible, but unlikely that I somehow left  
>>>>>>>>> this
>>>>>>>>> code in a state that had a compiler error a couple of months  
>>>>>>>>> ago
>>>>>>>>> when I last looked at this app)  I'll be looking at this  
>>>>>>>>> more, but
>>>>>>>>> I wanted to send a note in case anyone else is seeing  
>>>>>>>>> something
>>>>>>>>> similar or has any ideas.
>>>>>>>>>
>>>>>>>>> org.openlaszlo.sc.CompilerError: main.lzx: 41: Error:  
>>>>>>>>> Incorrect
>>>>>>>>> number of arguments. Expected no more than 2, in line:
>>>>>>>>> flash.external.ExternalInterface.addCallback("playMedia",  
>>>>>>>>> null,
>>>>>>>>> playMedia)
>>>>>>>>>
>>>>>>>>> The Flash docs indicate that there are three arguments:
>>>>>>>>> http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001653.html
>>>>>>>>> <http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001653.html 
>>>>>>>>> >
>>>>>>>>>
>>>>>>>>> Also, is there any LZX-native way that I should be making this
>>>>>>>>> call instead of devolving into calling Flash directly?
>>>>>>>>>
>>>>>>>>> Thanks in advance,
>>>>>>>>> Sarah
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> -- 
>>>>>>>>> Henry Minsky
>>>>>>>>> Software Architect
>>>>>>>>> hminsky at laszlosystems.com <mailto:hminsky at laszlosystems.com>
>>>>>>>>>
>>>>>>>>>
>>>>>>>> http://www.ultrasaurus.com
>>>>>>>
>>>>>>> -- 
>>>>>>> Regards,
>>>>>>> Max Carlson
>>>>>>> OpenLaszlo.org
>>>>>> http://www.ultrasaurus.com
>>>>>
>>>>> -- 
>>>>> Regards,
>>>>> Max Carlson
>>>>> OpenLaszlo.org
>>>> http://www.ultrasaurus.com
>>>
>>> -- 
>>> Regards,
>>> Max Carlson
>>> OpenLaszlo.org
>> http://www.ultrasaurus.com
>
> -- 
> Regards,
> Max Carlson
> OpenLaszlo.org

http://www.ultrasaurus.com






More information about the Laszlo-dev mailing list