我是一个Java爱好者
分类:
2010-05-25 10:12:32
Flex端程序
源代码TestFlex_Flash.mxml
import flash.profiler.showRedrawRegions;
import mx.controls.Alert;
import flash.utils.Timer;
import flash.events.TimerEvent;
public function testf():void{
Alert.show("已经调用");
trace("ljlo");
var time:Timer=new Timer(1000,1);
time.start();
time.addEventListener(TimerEvent.TIMER_COMPLETE,invokeFlash);
}
public function loadSwf():void{
//传入此flex对象
Object(swfgame.content).setApp(this);
// Object(swfgame.content).toFlex();
}
public function invokeFlash(inovevent:TimerEvent):void{
//调用flash组件实例类对象的方法(myC为在flash帧中定义)
Object(swfgame.content).myC.innerFunction();
}
public function parentMethod():void{
Alert.show("调用父方法......");;
}
]]>
源代码TestComponent.mxml
import mx.controls.Alert;
public function testf():void{
Alert.show("class组件已经调用了....");
trace("ljlo");
}
]]>
源代码VisualView.as
package
{
import mx.core.IMXMLObject;
import mx.controls.Alert;
public class VisualView implements IMXMLObject
{
protected var view : Object;
protected var id : String;
public function initialized( document : Object, id : String ) : void
{
this.view = document;
this.id = id;
}
public function VisualView()
{
}
public function testView():void{
Alert.show("调用无视图方法。");
}
Public function invokeFlashMethod():void{
Object(View.parentApplication.swfgame.content).
myC.innerFunction();
}
}
}
Flash端程序
Flash帧里代码如下
import flash.utils.Timer;
import flash.events.TimerEvent;
var flexApp:Object;
function setApp(ap:Object):void {
this.flexApp=ap;
// myC.passFlex(flexApp);
var time:Timer=new Timer(1000,1);
time.start();
time.addEventListener(TimerEvent.TIMER_COMPLETE,toFlex);
}
var myC:MyClass=new MyClass();
function toFlex(eve:TimerEvent){
flexApp.component.testf(); //flash调用flex子组件方法
flexApp.component.view.testView(); //flash调用flex非可视组件组件中方法
flexApp.testf(); //flash直接调用flex加载该游戏作用域内方法
flexApp.component.parentApplication.parentMethod(); //flash调用flex父组件方法
myC.passFlex(flexApp);
}
MyClass类源代码
package {
public class MyClass {
public var myObj:Object=null;
public function MyClass() {
}
public function passFlex(obj:Object) {
//obj.testf();
myObj=obj;
}
public function innerFunction(){
//myObj.component.testf();
trace("i am from the flash inner class")
}
}
}