ITeye博客

flex学习笔记1

fourfire · 2007-07-19 09:07 · flex · 非技术 · Markdown

1 dynamic change the style on runtime
 

as 代码

 

  1. import mx.styles.StyleManager;
  2. import mx.events.StyleEvent;
  3. 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. trace(type.name); // outputs "MyClass"
  3. trace(type.fullName); // outputs "com.domain::MyClass"
  4. trace(type.methods);
  5. trace(type.staticConstants);
  6. trace(type.staticVariables);
  7. trace(type.constants);
  8. trace(type.variables);
  9. for(var i:int=0;i
  10. {
  11. var m:Method=type.methods[i];
  12. trace("method:"+m.name);
  13. if(m.name=="show"){
  14. m.invoke(instance,"KKK");
  15. }
  16. }

you can get the framework on sourceforge.net/projects/prana/

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。