如何使用swc内部组件的中继器
我用Flash CS5构建了一个swc文件,其中包含一些界面组件,如TextInput、Label。 然后我在 Flex 程序中使用它。
但是当我想为这个组件使用 Flex Repeater 时,我遇到了问题。
以下是我自己使用Flash CS在swc文件中定义的一个组件。
package {
import fl.controls.TextInput;
......
public dynamic class MyWindow extends UIMovieClip {
public var txt1 : TextInput;
......
}
}
}
然后我在我的 Flex 程序中使用它,如下所示:
<local:MyWindow id="myWindow"/>
<fx:Script>
<![CDATA[
......
private function Init() : void {
myWindow.txt1.text = "myText";
}
......
]]>
</fx:Script>
它运行良好。
但是如何直接在mxml中使用txt1呢?像这样:
<local:MyWindow id="myWindow" txt1.text="myText"/>
我知道它不起作用,但我想使用转发器创建一些类似的MyWindow,它需要绑定dataProvider。我写了这样的弹性代码:
<mx:VBox>
<mx:Repeater x="10" y="10" id="multiWindow">
<local:MyWindow txt1.text="{multiWindow.currentItem}"/>
</mx:Repeater>
</mx:VBox>
但它不能工作。
有谁知道如何让它发挥作用?谢谢。
=================================================== =================================
更新代码,多窗口完整代码是:
package {
import fl.controls.TextInput;
import mx.flash.UIMovieClip;
import flash.display.DisplayObject;
import flash.events.EventDispatcher;
import flash.display.Sprite;
import flash.display.InteractiveObject;
import flash.display.MovieClip;
import flash.display.DisplayObjectContainer;
public dynamic class MyWindow extends UIMovieClip {
public var txt1 : TextInput;
public var txt2 : TextInput;
public var txt3 : TextInput;
}
}
I build a swc file by Flash CS5 contains some interface component like TextInput, Label.
And then I use it in a flex program.
But I meet the problem when I want use flex repeater for this component.
Following is the a component defined by myself in swc file using Flash CS.
package {
import fl.controls.TextInput;
......
public dynamic class MyWindow extends UIMovieClip {
public var txt1 : TextInput;
......
}
}
}
Then I use it in my flex program like this:
<local:MyWindow id="myWindow"/>
<fx:Script>
<![CDATA[
......
private function Init() : void {
myWindow.txt1.text = "myText";
}
......
]]>
</fx:Script>
it works well.
But how can I use txt1 in mxml directly? like this:
<local:MyWindow id="myWindow" txt1.text="myText"/>
I know it doesn't work, but I want use repeater to create some similar MyWindow, it need bind the dataProvider. I wrote flex code like this:
<mx:VBox>
<mx:Repeater x="10" y="10" id="multiWindow">
<local:MyWindow txt1.text="{multiWindow.currentItem}"/>
</mx:Repeater>
</mx:VBox>
But it can't work.
Does anyone know how to make it work? Thanks.
=================================================================================
Update code, multiWindow complete code is :
package {
import fl.controls.TextInput;
import mx.flash.UIMovieClip;
import flash.display.DisplayObject;
import flash.events.EventDispatcher;
import flash.display.Sprite;
import flash.display.InteractiveObject;
import flash.display.MovieClip;
import flash.display.DisplayObjectContainer;
public dynamic class MyWindow extends UIMovieClip {
public var txt1 : TextInput;
public var txt2 : TextInput;
public var txt3 : TextInput;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要在 MX 容器中使用的任何组件都需要实现 IUIComponent。我相信 Flash 有一个内置基类,您可以扩展它以与 Flex 一起使用,但您也可以执行以下操作:
请注意,如果您没有考虑 Flex 组件生命周期和布局系统,它可能会玩不好。
Any component that you want to use withing an MX container needs to implement IUIComponent. I believe that Flash has a built in base class that you can extend for use with Flex, but you can also just do something like this:
Note that if you haven't given thought to the Flex Component life cycle and layout system, it might not play well.