0
votes

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;
}
}
1

1 Answers

1
votes

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:

<mx:VBox>
     <mx:Repeater x="10" y="10" id="multiWindow">
         <mx:UIComponent>
             <local:MyWindow txt1.text="{multiWindow.currentItem}"/>
         </mx:UIComponent>
     </mx:Repeater> 
</mx:VBox>

Note that if you haven't given thought to the Flex Component life cycle and layout system, it might not play well.