flex学习笔记1

1 dynamic change the style on runtime
 
as 代码
 
  1. import mx.styles.StyleManager;  
  2. import mx.events.StyleEvent;  
  3.   
  4. var styleEvent:IEventDispatcher = StyleManager.loadStyleDeclarations( name, true );

the name parameter is a swf file that is compiled by a css file        
 etc:'style1.swf'
2 alert function
as 代码
 
  1. import mx.controls.Alert;   
  2. Alert.show('');   


3 reflection invoke
my class
as 代码
 
  1. package com.firebow  
  2. {  
  3.     import mx.controls.Alert;   
  4.     public class Caller  
  5.     {  
  6.         public function show(str:String="abc",other:String=null):void  
  7.         {  
  8.             Alert.show(str);  
  9.         }  
  10.     }  
  11. }  
invoke method show
as 代码
 
  1. var classReference:Class = flash.utils.getDefinitionByName("com.firebow.Caller") as Class;  
  2.                 var instance:Object=new classReference();  
  3.                 var args:Array=new Array();  
  4.                 args[0]="abc";  
  5.                 args[1]="null";  
  6.                 instance["show"].apply(instance,args);  

you can use the pranaframework,it supply some packages ,include reflection
for example
as 代码
 
  1. var type:Type =Type.forInstance(instance);  
  2.                   
  3. trace(type.name); // outputs "MyClass"  
  4.   
  5. trace(type.fullName); // outputs "com.domain::MyClass"  
  6.   
  7. trace(type.methods);  
  8.   
  9. trace(type.staticConstants);  
  10.   
  11. trace(type.staticVariables);  
  12.   
  13. trace(type.constants);  
  14.   
  15. trace(type.variables);  
  16.   
  17. for(var i:int=0;i
  18. {  
  19.     var m:Method=type.methods[i];  
  20.     trace("method:"+m.name);  
  21.     if(m.name=="show"){  
  22.         m.invoke(instance,"KKK");  
  23.     }  
  24. }  
you can get the framework on sourceforge.net/projects/prana/

你可能感兴趣的:(.net,css,Flex,Flash)