Or if you want your origional code to work call this.validateNow() not
foo.validateNow().  Its the parents job to size the child not the childs job
to size itself.  This was stated in Beau Scott's email but may have passed
you by.

On Fri, Aug 28, 2009 at 10:06 PM, Wesley Acheson
<[email protected]>wrote:

> This may help or not.  Its a bit of a hack. but if your always resizing
> children when the size of the container changes I may just leave it in as a
> permenant event listener.
>
> Regards,
>
> Wesley
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml";
> layout="absolute" creationComplete="init();" initialize="maximize();"
> verticalScrollPolicy="off" horizontalScrollPolicy="off">
>    <mx:Script>
>        <![CDATA[
>            import mx.controls.Alert;
>            import mx.events.ResizeEvent;
>
>            private function clicked():void
>            {
>                foo.percentWidth = 50;
>                foo.invalidateSize();
>                foo.validateNow();
>                txtWidth.text = foo.width.toString();
>                foo.addEventListener(ResizeEvent.RESIZE, handleResize);
>                trace (foo.width);
>            }
>
>            private function handleResize(event:ResizeEvent):void{
>              Alert.show(event.target.width);
>              foo.removeEventListener(ResizeEvent.RESIZE, handleResize);
>            }
>        ]]>
>    </mx:Script>
>    <mx:HBox height="24" top="0" left="0" right="0">
>        <mx:Button click="clicked()" label="click me"/>
>    </mx:HBox>
>    <mx:Canvas id="foo" width="100%" left="182" top="63" bottom="0"
> borderColor="red" borderThickness="1" borderStyle="solid">
>
>    </mx:Canvas>
>
>    <mx:Text x="0" y="32" width="76" id="txtWidth"/>
>    <mx:Text x="0" y="60" text="{foo.width}" width="76"/>
> </mx:WindowedApplication>
>
>
>
>
> On Wed, Aug 26, 2009 at 9:45 PM, jmfillman <[email protected]> wrote:
>
>> The code below should demonstrate the issue more specifically.
>>
>> What you get when the clicked() function is called, shows that there is a
>> slight delay in getting the width of the container. You'll note that the
>> trace statement returns the original width as does the txtWidth field.
>>
>> You will note, however, that if you bind to the width of the container,
>> you do get the correct width of the canvas. What I infer from this is that
>> there is a delay in FlashPlayer/Air in having the width value set.
>>
>> If, however, you use the previous example, posted Beau, this works,
>> presumably because the item you are re-sizing is within a container and the
>> LayoutManager deals with nested items first, as I recall.
>>
>> Why the validateNow() function doesn't complete before moving on to the
>> other two elements in the clicked() function, wasn't what I expected. This
>> is probably a speed thing in the function so as to not hold up other items
>> while the item is being validated???
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml";
>> layout="absolute" creationComplete="init();" initialize="maximize();"
>> verticalScrollPolicy="off" horizontalScrollPolicy="off">
>>    <mx:Script>
>>        <![CDATA[
>>
>>            private function clicked():void
>>            {
>>                foo.percentWidth = 50;
>>                foo.invalidateSize();
>>                foo.validateNow();
>>                txtWidth.text = foo.width.toString();
>>                trace (foo.width);
>>            }
>>        ]]>
>>    </mx:Script>
>>    <mx:HBox height="24" top="0" left="0" right="0">
>>         <mx:Button click="clicked()" label="click me"/>
>>     </mx:HBox>
>>    <mx:Canvas id="foo" width="100%" left="182" top="63" bottom="0"
>> borderColor="red" borderThickness="1" borderStyle="solid">
>>
>>    </mx:Canvas>
>>
>>    <mx:Text x="0" y="32" width="76" id="txtWidth"/>
>>    <mx:Text x="0" y="60" text="{foo.width}" width="76"/>
>> </mx:WindowedApplication>
>>
>> --- In [email protected], Beau Scott <beau.sc...@...> wrote:
>> >
>> > You'll need to invalidate the component's parent's size and revalidate
>> it
>> > before your target's size is computed:
>> >
>> > <?xml version="1.0" encoding="utf-8"?>
>> > <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml";
>> > layout="vertical">
>> >     <mx:Script>
>> >         <![CDATA[
>> >             import mx.core.UIComponent;
>> >             private function clicked():void
>> >             {
>> >                 trace(bar.width);
>> >                 bar.percentWidth = bar.percentWidth == 100 ? 50 : 100;
>> >                 UIComponent(bar.parent).invalidateSize();
>> >                 UIComponent(bar.parent).validateNow();
>> >                 trace(bar.width);
>> >             }
>> >         ]]>
>> >     </mx:Script>
>> >     <mx:Box id="foo" width="100%" height="50" borderColor="red"
>> > borderThickness="1" borderStyle="solid">
>> >         <mx:Box id="bar" width="100%" height="100%" borderColor="blue"
>> > borderThickness="1" borderStyle="solid" />
>> >     </mx:Box>
>> >     <mx:Button click="clicked()" label="click me" />
>> > </mx:WindowedApplication>
>> >
>> >
>> > Run that and click the button to see the trace output.
>> >
>> >
>> > HTH,
>> >
>> > Beau
>> >
>> >
>> >
>> >
>> > On Wed, Aug 26, 2009 at 10:04 AM, jmfillman <jmfill...@...> wrote:
>> >
>> > >
>> > >
>> > > If you trace the width and measuredWidth immediately after setting the
>> > > percentWidth, both width and measuredWidth show the original width
>> instead
>> > > of the updated width.
>> > >
>> > >
>> > > --- In [email protected] <flexcoders%40yahoogroups.com>,
>> > > "valdhor" <valdhorlists@> wrote:
>> > > >
>> > > > What does canvas.measuredWidth give when the user clicks the button?
>> > > >
>> > > >
>> > > > --- In [email protected] <flexcoders%40yahoogroups.com>,
>> > > "jmfillman" <jmfillman@> wrote:
>> > > > >
>> > > > > I have a canvas container with="100%". When the user clicks a
>> button,
>> > > the container is set to percentWidth=20, and I need to immediately
>> know the
>> > > new width so that I can properly re-size elements in the container to
>> match
>> > > the new width.
>> > > > >
>> > > > > From what I can tell, the LayoutManager doesn't get to measuring
>> the
>> > > new width of the container right away. If the user clicks the button
>> again,
>> > > the LayoutManager has done it's thing and has set the width value of
>> the
>> > > canvas.
>> > > > >
>> > > > > So the question is, how do I get the new width of the canvas as
>> soon as
>> > > I set percentWidth=20?
>> > > > >
>> > > >
>> > >
>> > >
>> > >
>> >
>> >
>> >
>> > --
>> > Beau D. Scott
>> > Software Engineer
>> >
>>
>>
>>
>>
>> ------------------------------------
>>
>> --
>> Flexcoders Mailing List
>> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
>> Alternative FAQ location:
>> https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
>> Search Archives:
>> http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups
>> Links
>>
>>
>>
>>
>

Reply via email to