admin管理员组文章数量:1327525
I have an actionscript function that loads an external swf and is currently linked to a button in the same swf...
function btnClick(event:MouseEvent):void{
SoundMixer.stopAll();
removeChild(loader);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSWFLoaded);
loader.load(movieSWF)
loader.x=Xpos
loader.y=Ypos
addChild(loader)
}
button.addEventListener(MouseEvent.CLICK,btnClick);
I'm wondering if there is a way to call this function from a link on the page that the swf is housed on. I'm guessing javascript, php or swfaddress would be the most likely way, but I'm unbelievably new to all this so I'm not sure where to start or how to go about it.
Any help would be appreciated.
I have an actionscript function that loads an external swf and is currently linked to a button in the same swf...
function btnClick(event:MouseEvent):void{
SoundMixer.stopAll();
removeChild(loader);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSWFLoaded);
loader.load(movieSWF)
loader.x=Xpos
loader.y=Ypos
addChild(loader)
}
button.addEventListener(MouseEvent.CLICK,btnClick);
I'm wondering if there is a way to call this function from a link on the page that the swf is housed on. I'm guessing javascript, php or swfaddress would be the most likely way, but I'm unbelievably new to all this so I'm not sure where to start or how to go about it.
Any help would be appreciated.
Share Improve this question asked Apr 5, 2010 at 5:03 wdense51wdense51 251 silver badge5 bronze badges1 Answer
Reset to default 9You're looking for the ExternalInterface.addCallback
function. This lets you register a function so that it can be called externally from JavaScript code.
Your HTML might look like this (where 'IDofSWF'
is the ID of the element containing the SWF on the page):
<a href="#" onclick="document.getElementById('IDofSWF').clicky()">
Click to call btnClick in the SWF
</a>
With the following in your initialization code in Flash:
import flash.external.ExternalInterface;
// ...
// This will allow JavaScript to call a function on the SWF named 'clicky'. It will execute the anonymous function passed as the second argument:
ExternalInterface.addCallback('clicky', function () {
btnClick(null);
});
Note that you won't get a MouseEvent (my example passes null
as the value for it) because the event handler is being called manually (externally from JavaScript) instead of from within the SWF on a mouse click.
本文标签: Calling AS3 function from html linkJavascript php swfaddressStack Overflow
版权声明:本文标题:Calling AS3 function from html link - Javascript? php? swfaddress? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742195953a2431082.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论