Call an as method from JS

Source: Internet
Author: User
Tags date html page unique id
JS calls an as method from JS:
To call the As method from JS, you have to make sure that four files are included in your HTML document:
<script type= "Text/javascript" src= "/path/to/exception.js" ></script>
<script type= "Text/javascript" src= "/path/to/flashtag.js" ></script>
<script type= "Text/javascript" src= "/path/to/flashserializer.js" ></script>
<script type= "Text/javascript" src= "/path/to/flashproxy.js" ></script>
<script type= "Text/vbscript" src= "/path/to/vbcallback.vbs" ></script> flashproxy.js (JavaScript Class) to proxy the method call between Flash and JS. Flashproxy and the flash you want to call the Flash method must share a unique ID so that flashproxy knows which flash on the page provides the calling method. The easiest way to create a unique ID is to use the time label. Write in your script:
var uid = new Date (). GetTime (); Now let's create a Flashproxy JavaScript class instance and pass the unique ID you just created to flash. Your Flash ID or name (the attribute value of the ID in the object tag and the attribute value of name in the embed tag), and the path to the javascriptflashgateway.swf file, like this:
var flashproxy = new Flashproxy (uid, ' myflashcontent ', '/path/to/javascriptflashgateway.swf '); NOTE: Flash's ID or name is "Myflashcontent".
When you embed flash in your HTML page, you have to use Flashvars to pass the unique ID (UID) that you pass to the Flashproxy constructor, and you have to add and pass it to your flash to the Flashproxy builder. Myflashcontent value of the same ID or name (the property value of the ID in the object label and the property value of name in the embed label). The Flashtag Class (Flashtag.js) in the file makes these simple:
<script type= "Text/javascript" >
var tag = new Flashtag ('/path/to/flashcontent.swf ', 300, 300, ' 7,0,14,0 '); Path, width, height, flashplayer version number
Tag.addflashvars (' lcid= ' + uid);//Passed parameters
Tag.setid (' myflashcontent ');/set <object id= "Myflashcontent" >
Tag.write (document);//write HTML code
</script> above, we write to lcid=+ uid.  The unique ID is passed to flash via the lcId, the flash variable. Up to now we have done the preparation work, through the Flashproxy instance from JS to invoke the Flash method, the department, as follows:
Flashproxy.call (' myactionscriptfunction ', ' My string ', 123, True, new Date (), NULL); The first parameter is the name of the Flash method you want to invoke, and the other parameters pass the same arguments as if this function were called in Flash. Supported data types include objects, arrays, strings, dates, numbers, booleans, nulls, and undefined.
All right. Verify that our myflashcontent.swf has referenced and initialized a Javascriptproxy object to accept these function invocation commands (refer to the "receive a call in Flash" of a JS method).
For more advanced usage examples, the Flashproxy object provides an additional optional parameter called "Callbackscope" (Temporary: return range). If you want flash to invoke a method in a larger scope than the current document, pass a parameter to the area you want to reach. For example, I have a JS object called "Callback", and I can instantiate the flashproxy so that the method invoked in Flash is attached to an instance of "callback":
var flashproxy = new Flashproxy (uid, ' myflashcontent ', '/path/to/javascriptflashgateway.swf ', callback);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.