actionscript + javascript

ⅰ亾dé卋堺 提交于 2019-12-01 11:54:45

Let's compile those answers together for AS2 and AS3 using JS injection AND the ExternalInterface (both ways work in BOTH languages)

AS2:


// to use javascript injection in a url request
getURL("javascript:displayPost(" + postId + "," + feedId +");", "_self");

// to use the external interface
import flash.external.ExternalInterface;
ExternalInterface.call("displayPost",postId,feedId);

AS3:


// to use javascript injection in a url request
navigateToURL(new URLRequest("javascript:displayPost(" + postId + "," + feedId +");"), "_self");

// to use the external interface
import flash.external.ExternalInterface;
ExternalInterface.call("displayPost",postId,feedId);

Notice that in AS2 and AS3 the ExternalInterface method is the exact same (ExternalInterface was introduced in Flash 8 for AS2). And in AS2 and AS3 the javascript injection method are the same except that it's navigateToURL instead of getURL, and the url string is wrapped in new URLRequest(), because it needs a URLRequest object. Also when using javascript injection, it's a good practice to set the target window to "_self" to avoid a new tab or window from opening.

Also incase anyone in the future is looking at this question the Actionscript 3 version of altCognito's answer is like this:

ExternalInterface.call("displayPost",postId,feedId);
  getURL("javascript:displayPost(" + postId + "," + feedId +")");

From:

You can also look into the following:

http://osflash.org/projects/flashjs/tutorials/jstoas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!