Accessing an ActionScript function via Javascript

后端 未结 2 580
予麋鹿
予麋鹿 2021-02-09 17:21

I\'m trying to call a function in an action script using the ExternalInterface.addCallback API, but I can\'t seem to get it to work. Here\'s what I have:

A

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-09 18:00

    I figured it out. The key way to signal the javascipt through ExternalInterface.call so we know for sure that the swf is loaded. The most "Universal" way to do this is as follows:

    MyClass.as

    //MyClass.as  
    package {
    
        import flash.display.Sprite;
        import flash.external.ExternalInterface;
    
        public class MyClass extends Sprite
        {
            public function MyClass()
            {
                ExternalInterface.addCallback('getStringJS', getStringAS);
                if  (ExternalInterface.available) {
                    ExternalInterface.call("isConnectedFlex");
                }
            }
    
            public function getStringAS():String
            {
                return "Hello World!";
            }
        }
    }
    

    index.html

    
    
        
            User Identification
        
        
            
                
                
            
            
        
    
    

提交回复
热议问题