1 dynamic change the style on runtime
the name parameter is a swf file that is compiled by a css file
etc:'style1.swf'
2 alert function
3 reflection invoke
my class
invoke method show
you can use the pranaframework,it supply some packages ,include reflection
for example
you can get the framework on
sourceforge.net/projects/prana/
as 代码
- import mx.styles.StyleManager;
- import mx.events.StyleEvent;
- 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 代码
- import mx.controls.Alert;
- Alert.show('');
3 reflection invoke
my class
as 代码
- package com.firebow
- {
- import mx.controls.Alert;
- public class Caller
- {
- public function show(str:String="abc",other:String=null):void
- {
- Alert.show(str);
- }
- }
- }
as 代码
- var classReference:Class = flash.utils.getDefinitionByName("com.firebow.Caller") as Class;
- var instance:Object=new classReference();
- var args:Array=new Array();
- args[0]="abc";
- args[1]="null";
- instance["show"].apply(instance,args);
you can use the pranaframework,it supply some packages ,include reflection
for example
as 代码
- var type:Type =Type.forInstance(instance);
- trace(type.name); // outputs "MyClass"
- trace(type.fullName); // outputs "com.domain::MyClass"
- trace(type.methods);
- trace(type.staticConstants);
- trace(type.staticVariables);
- trace(type.constants);
- trace(type.variables);
- for(var i:int=0;i
- {
- var m:Method=type.methods[i];
- trace("method:"+m.name);
- if(m.name=="show"){
- m.invoke(instance,"KKK");
- }
- }
本文介绍了如何在Flex中动态更改样式以及使用反射调用类的方法。首先通过加载SWF文件来实现运行时的样式变更;其次展示了如何利用Alert显示消息;最后详细解释了通过反射调用类的方法,并提供了具体的代码示例。
1937

被折叠的 条评论
为什么被折叠?



