是否可以从javascript发送按键和鼠标移动到flash对象?

时间:2011-06-02 19:15:27

标签: flash

是否可以从javascript发送按键和鼠标移动到flash对象以进行测试?

1 个答案:

答案 0 :(得分:2)

请参阅SWFObject文档(特别是getObjectById和embedSWF)和flash.external.ExternalInterface

在ActionScript中,

package
{
    import flash.external.*

    public class MySprite extends Sprite {
    function MySprite():void 
    {
        ExternalInterface.addCallback("handleEventInAS", handleEventInAS);
    }

    function handleEventInAS(e:Object) 
    { 
       trace("in handleEventInAS with e="+e);
    }
}

然后在HTML / JS中,

 <script src="swfobject.js"></script>
 <script>

     swfobject.embedSWF("myflash.swf","myflashid","100","100",9);
     var flashobj = swfobject.getObjectById("myflashid");
     window.onmousemove = connectjs2as;

     function connectjs2as(e)
     {
        if(flashobj)
            flashobj.handleEventInAS(e);
     }
 </script>

注意:需要FlashPlayer 9,这就是我在embedSWF()调用中添加'9'的原因。