日期:2014-05-20  浏览次数:20701 次

FLEX中怎样才能使得as和mxml相互得到各自的引用
我在同一个包下定义了两个类,分别如下:
TextScript.as
package cee.view{

public class TextScript extends Text{

private var text:Text;

public function TextScript(text:Text){
this.text=text;
}
}
}
Text.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009"  
xmlns:s="library://ns.adobe.com/flex/spark"  
xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" width="400" height="300">
<fx:Script>
<![CDATA[
private var textScript:TextScript=new TextScript(this);
]]>
</fx:Script>
</mx:Module>
这样写会报错。
怎样才能使得Text.mxml中得到TextScript.as的引用的同时,
使得TextScript.as得到Text.mxml的引用

------解决方案--------------------
private var textScript:TextScript=new TextScript(this);
你确定Text已经实例化?
LZ请去了解一些类的实例化顺序
--------------------------------------------------
private var textScript:TextScript = null;

onCreationComplement(){
textScript = new TextScript(this);
}
------解决方案--------------------
正要学,飘一下
------解决方案--------------------
private var textScript:TextScript=new TextScript(this);

this指向text.mxml定义的Module,和Text不是同一种类型,会报错的