flex 打开外部的swf 并调用其方法

主要是MovieClip(swfLoader.content).flashFun();

如果要动态的设置方法MovieClip(swfLoader.content)[字符串变量]();

 

代码
<? xml version = " 1.0 "  encoding = " utf-8 " ?>
< mx:WindowedApplication xmlns:mx = " http://www.adobe.com/2006/mxml "  layout = " absolute " >
    
< mx:Script >     
        
<! [CDATA[   
          
            import flash.filesystem.File;     
            import flash.events.FileListEvent;   
            import flash.events.Event;   
            import flash.net.FileFilter;
           
            
/* *   
             * 选择一个文件   
             
*/    
           
            
private  function tanFile(titleStr:String): void {   
                var file:File 
=   new  File();  
                var openFileFilter:FileFilter 
=   new  FileFilter( " Flash影片 " " *.swf " );   // 过滤文件 
                  file.browseForOpen(titleStr,[openFileFilter]);   
                   file.addEventListener(Event.SELECT, fileSelectpd);   
            }     
               
            
private  function fileSelectpd(e:Event): void  {    
                inputID.text 
=  e.target.nativePath;     // 绝对路径   
                  swfld.source = inputID.text;
            }   
           
private  function flexToFlash(): void
           {
                   
               MovieClip(swfld.content)[cmdText.text]();
           }    
                          
        ]]
>    
    
</ mx:Script >    
    
< mx:Button id = " butFileID "  y = " 30 "  label = " 选择一个文件 "  click = " tanFile('选择一个swf文件'); "   x = " 10 " />    
       
    
< mx:TextInput id = " inputID "  y = " 30 "  width = " 448 "  x = " 110 " />  
    
< mx:SWFLoader x = " 10 "  y = " 167 "  width = " 608 "  height = " 449 "  id = " swfld " />
    
< mx:Button x = " 420 "  y = " 60 "  label = " 执行方法 "  click = " flexToFlash() "  width = " 138 "  height = " 50 " />
    
< mx:TextInput x = " 110 "  y = " 60 "  width = " 282 "  text = " 如:gotoAndPlay "  id = " cmdText " />
    
< mx:Label x = " 10 "  y = " 60 "  text = " 输入方法名称 "  fontSize = " 12 " />
</ mx:WindowedApplication >

 

 

你可能感兴趣的:(Flex)