最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Calling AS3 function from html link - Javascript? php? swfaddress? - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 9

You'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.

发布评论

评论列表(0)

  1. 暂无评论