Hi,

Here is a partial solution to ur issue. The problem here is when you add a controlbar to the Panel as a child, you also need to tell the panel that the added Child is of the type controlBar. Once this property is set, the Panel itself takes care of layouting the controlbar at the required position. However adding a chind to programmatically added controlbar seems to be broken, I have logged a bug into the adobe bugbase to track this. In the meanwhile modify your ControlBarInPanel.as with the following code.

The only modifications that i have done is extending the class from Panel and not from Canvas.

The code:


package
{
    import mx.containers.Canvas ;
    import mx.containers.Panel;
    import mx.containers.ControlBar;
    import mx.controls.Button;
    import mx.events.FlexEvent;
  
    public class ControlBarInPanel extends Panel
    {
        public function ControlBarInPanel()
        {
            super();
            addEventListener( FlexEvent.CREATION_COMPLETE, handleCreationComplete );
        }
      
        private function handleCreationComplete( event:FlexEvent ):void
        {
        
        }
        override protected function createChildren():void
        {
            super.createChildren()
            var tb:Button = new Button();
            tb.label = "Test Button in Panel";

            var cb:ControlBar = new ControlBar();
            var tb2:Button = new Button();
            tb2.label = "Test Button in Control Bar";
            cb.addChild( tb2 );
            cb.includeInLayout=true
           
          
        
            addChild( tb );
            addChild(tb)
            addChild(cb);
           
         
            controlBar = cb;
            //cb.invalidateDisplayList()
        }
    }
}


Hope this helps
Harish

On 9/14/06, aaron smith < [EMAIL PROTECTED]> wrote:

I've been just messing around with how to do things through code. It seems adding a ControlBar to a panel in code doesn't do the same thing as it does in mxml.

here is my mostly code example:

MXML:

<?xml version=" 1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml " layout="vertical" creationComplete="initApp()">
    <mx:Script>
        import ControlBarInPanel;
       
        private function initApp():void
        {
            var cbip:ControlBarInPanel = new ControlBarInPanel();
            addChild( cbip );
        }
    </mx:Script>
</mx:Application>

AS3:

package
{
    import mx.containers.Canvas;
    import mx.containers.Panel;
    import mx.containers.ControlBar;
    import mx.controls.Button;
    import mx.events.FlexEvent;
   
    public class ControlBarInPanel extends Canvas
    {
        public function ControlBarInPanel()
        {
            super();
            addEventListener( FlexEvent.CREATION_COMPLETE, handleCreationComplete );
        }
       
        private function handleCreationComplete( event:FlexEvent ):void
        {
            percentWidth = 100;
            percentHeight = 100;
            var tb:Button = new Button();
            tb.label = "Test Button in Panel";
           
            var p:Panel = new Panel();
            p.title = "Test Control Bar in Panel";

            var cb:ControlBar = new ControlBar();
           
            var tb2:Button = new Button();
            tb2.label = "Test Button in Control Bar";
           
            addChild( p );
            p.addChild( tb );
            p.addChild( cb );
            cb.addChild( tb2 );
        }
    }
}


this all works fine, but when the control bar gets added to the panel it is inside of the White content Area in the panel.

Now when I do the same thing but with MXML::

<?xml version="1.0" encoding="utf-8" ?>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml " layout="vertical">
<mx:Canvas percentWidth="100" percentHeight="100" >
    <mx:Panel title="Test Control Bar in Panel">
        <mx:Button label="Test Button in Panel" />
        <mx:ControlBar horizontalAlign="right">
            <mx:Button label="Test Button in ControlBar" />
        </mx:ControlBar>
    </mx:Panel>
</mx:Canvas>
</mx:Application>



it puts the control bar under the white content area in a panel.




what is going on behind the scenes in mxml that is causing the difference??





__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to