duancong7573 2010-04-05 05:03
浏览 80
已采纳

从html链接调用AS3函数 - Javascript? PHP的? swfaddress?

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.

  • 写回答

1条回答 默认 最新

  • dtn51137 2010-04-05 12:51
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持