---
title: "flex学习笔记1"
author: "fourfire"
date: "2007-07-19T09:07:47Z"
tags: []
categories: ["非技术"]
slug: "flex-1"
draft: false
lastmod: "2007-07-19T09:07:47Z"
id: 102681
url: "https://fourfire.iteye.com/blog/102681"
---

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 代码

 

01. package com.firebow
02. {
03. import mx.controls.Alert;
04. public class Caller
05. {
06. public function show(str:String="abc",other:String=null):void
07. {
08. Alert.show(str);
09. }
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 代码

 

01. var type:Type =Type.forInstance(instance);
02. trace(type.name); // outputs "MyClass"
03. trace(type.fullName); // outputs "com.domain::MyClass"
04. trace(type.methods);
05. trace(type.staticConstants);
06. trace(type.staticVariables);
07. trace(type.constants);
08. trace(type.variables);
09. 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/](http://sourceforge.net/projects/prana/)