K, figured out a solution.

 

In the base control the list items are public vars and created by me in the init, and then they are available in the child.

 

Jeff

 

 

Base control

 

<?xml version="1.0" encoding="utf-8"?>

<!-- selector.mxml -->

<mx:HBox xmlns:mx="http://www.macromedia.com/2003/mxml"

width="100%" height="100%"

horizontalAlign="center" vScrollPolicy="off" hScrollPolicy="off"

marginBottom="0" marginRight="0" marginTop="0" marginLeft="0" x="0" y="-5"

initialize="formInit();">

<mx:Script>

<![CDATA[

            import mx.controls.List;

 

            public var SelectedValues:Array;

            public var SourceValues:Array;

            public var currentSecurityKeys:List;

            public var allSecurityKeys:List;

           

            function formInit() : Void

            {

                        currentSecurityKeys = List(currentVBox.createChild(List, undefined, ""));

                        currentSecurityKeys.dataProvider = SelectedValues;

                        allSecurityKeys = List(allSecurityVBox.createChild(List, undefined, ""));

                        allSecurityKeys.dataProvider = SourceValues;

            }

]]>

</mx:Script>

            <mx:VBox id="currentVBox" height="100%" verticalAlign="middle">

            </mx:VBox>

            <mx:VBox height="100%" verticalAlign="middle">

                        <mx:Button id="allToLeft" label="&lt;&lt;"/>

                        <mx:Button id="toLeft" label="&lt;"/>

                        <mx:Button id="toRight" label="&gt;"/>

                        <mx:Button id="allToRight" label="&gt;&gt;"/>

            </mx:VBox>

            <mx:VBox id="allSecurityVBox" height="100%" verticalAlign="middle">

            </mx:VBox>

</mx:HBox>

 

Child

 

<?xml version="1.0" encoding="utf-8"?>

<!-- SecuritySelector.mxml -->

<component:Selector xmlns:component="net.flex.component.core.*"

                                                            xmlns:mx="http://www.macromedia.com/2003/mxml" initialize="selectorInit();" >

<mx:Script>

<![CDATA[

            import net.flex.vo.security.*;

            import net.flex.vo.user.UserVO;

            public function selectorInit()

            {

                        currentSecurityKeys.labelFunction = mx.utils.Delegate.create(this,SourceLabelFunctions);

            }

            public function SourceLabelFunctions ( item:Object ) :String

            {

                        var user:UserSecurityVO = UserSecurityVO(item);

                        return item.securityRole.roleName;

            }

]]>

</mx:Script>

</component:Selector>

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Jeff Krueger
Sent: Thursday, April 14, 2005 10:25 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Child control implementing a parents labelFunction

 

All,

 

            I am trying to create a component that has two list with a couple of buttons between the two list to allow the user to move items between the two list.  Pretty standard type of control.  The problem that I am having is that I want to be able to have a base control that handles the moving of the items between the two lists.  But I want the child instances to be able to control the labelFunction for each list in the component.  But whenever I assign anything to that function the compiler says only functions in document are allowed.  I am not sure how to expose a function reference to child objects.  I tried over riding the function in a child and that didn’t seem to work.  I am trying to do this in mxml instead of action script.  Here is the source for the control. 

 

Thanks

 

Jeff

 

<?xml version="1.0" encoding="utf-8"?>

<!-- selector.mxml -->

<mx:HBox xmlns:mx="http://www.macromedia.com/2003/mxml"

width="100%" height="100%"

horizontalAlign="center" vScrollPolicy="off" hScrollPolicy="off"

marginBottom="0" marginRight="0" marginTop="0" marginLeft="0" x="0" y="-5" >

<mx:Script>

<![CDATA[

 

            public var SelectedValues:Array;

            public var SourceValues:Array;

 

            public function SourceLabelFunction ( item:Object ) :String

            {

                        return "";

            }

 

]]>

</mx:Script>

            <mx:VBox height="100%" verticalAlign="middle">

                        <mx:List id="currentSecurityKeys"  >

                                    <mx:dataProvider> {SelectedValues} </mx:dataProvider>

                        </mx:List>

            </mx:VBox>

            <mx:VBox height="100%" verticalAlign="middle">

                        <mx:Button id="allToLeft" label="&lt;&lt;"/>

                        <mx:Button id="toLeft" label="&lt;"/>

                        <mx:Button id="toRight" label="&gt;"/>

                        <mx:Button id="allToRight" label="&gt;&gt;"/>

            </mx:VBox>

            <mx:VBox height="100%" verticalAlign="middle">

                        <mx:List id="allSecurityKeys" labelFunction="SourceLabelFunction">

                                    <mx:dataProvider> {SourceValues} </mx:dataProvider>

                        </mx:List>

            </mx:VBox>

</mx:HBox>

 

<<<<<<<<<<<<<<<<<<<<<Child source>>>>>>>>>>>>>>>>>>>>>>>>>>>>

<?xml version="1.0" encoding="utf-8"?>

<!-- SecuritySelector.mxml -->

<component:Selector xmlns:component="net.flex.component.core.*"

                                                            xmlns:mx="http://www.macromedia.com/2003/mxml" >

<mx:Script>

<![CDATA[

            import net.flex.vo.security.*;

            import net.flex.vo.user.UserVO;

            public function selectorInit()

            {

                       

            }

            public function SourceLabelFunction ( item:Object ) :String

            {

                        var user:UserSecurityVO = UserSecurityVO(item);

                        return item.securityRole.roleName;

            }

]]>

</mx:Script>

</component:Selector>

 

 

 



Yahoo! Groups Links

Reply via email to