Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4244058
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:39:31+00:00 2026-05-21T03:39:31+00:00

I have a window in which I want to add/remove component and resize the

  • 0

I have a window in which I want to add/remove component and resize the window accordingly based on states. but for some reason it’s ignoring the first resize.
here’s a sample code

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       minWidth="450"
                       minHeight="355"
                       currentState="{stateBox.selected ? 'one' : 'two'}"
                       currentStateChange="handleStateChange(event.oldState, event.newState)">

    <fx:Script>
        <![CDATA[
            private function handleStateChange(oldState:String, newState:String):void 
            {
                if (oldState == "two") {
                    width   -= 341;
                    minWidth    = 450;
                } else {
                    width   += 341;
                    minWidth    = 791;
                }
            }
        ]]>
    </fx:Script>

    <s:states>
        <s:State name="one" />
        <s:State name="two" />
    </s:states>
    <s:Rect id="rect1" top="0" left="0" right="0" right.two="341"  bottom="0" >
        <s:fill>
            <s:SolidColor color="0xDDDDDD" />
        </s:fill>
    </s:Rect>

    <s:Rect id="rect2" top="0" bottom="0" width="341" right="0" includeIn="two" >
        <s:fill>
            <s:SolidColor color="0x000000" />
        </s:fill>
    </s:Rect>

    <s:CheckBox id="stateBox" label="change state" />
</s:WindowedApplication>

Idea is that when the state change to ‘two’, I want to add rect2 to display and increase the minWidth and size of the window. And when the state change to ‘one’, i want to remove rect2 from display and resize the window. This seems to work except the window doesn’t shrink on the very first time the state change from “two” to “one” but works as expected afterwards. I’m not sure why it’s ignoring first time I reduce the width. I also tried changing nativeWindow.bounds directly but that didn’t work either.

Originally I just tried setting minWidth based on state (minWidth.one=”450 minWidth.two=”791″) but that caused window to grow on left and shrink on right which caused the window to move left whenever the state changed. so then I just moved the window to right whenever state changed but that caused some flicker that I didn’t want.

does anyone have any idea why this might be happening? or a good solution for my problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:39:32+00:00Added an answer on May 21, 2026 at 3:39 am

    Try flipping these lines around from:

                    width   -= 341;
                    minWidth    = 450;
    

    to:

                    minWidth    = 450;
                    width   -= 341;
    

    I think the problem is with the way that condition is setup in general…. I’m going to copy your code and modify it how I would go about doing this and repost as an edit, but you could try the above suggestion (I believe you may be setting the width lower than the minimum width then reducing the minWidth so the setting of the width in the first place would have been set to a width that isn’t valid according to the current minWidth, think you may only see this the first time around due to timing with validation.

    EDIT(ed twice, add locking the window size by setting min and max heights equal to the set height):

    <?xml version="1.0" encoding="utf-8"?>
    <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark"
                           xmlns:mx="library://ns.adobe.com/flex/mx"
                           minHeight="355"
                           maxHeight="355"
                           minWidth="450"
                           width.two="791"
                           width.one="450"
                           minWidth.one="450"
                           minWidth.two="791"
                           maxWidth.one="450"
                           maxWidth.two="791">
    
        <fx:Script>
            <![CDATA[
                protected function stateBox_changeHandler(event:Event):void
                {
                    // TODO Auto-generated method stub
                    currentState=stateBox.selected ? 'two' : 'one';
                }
            ]]>
        </fx:Script>
    
        <s:states>
            <s:State name="one"/>
            <s:State name="two"/>
        </s:states>
    
        <s:HGroup width="100%"
                  height="100%"
                  gap="0">
            <s:Rect width="450"
                    height="100%">
                <s:fill>
                    <s:SolidColor color="0xff0000"/>
                </s:fill>
            </s:Rect>
    
            <s:Rect width="341"
                    height="100%"
                    includeIn="two">
                <s:fill>
                    <s:SolidColor color="0x000000"/>
                </s:fill>
            </s:Rect>
        </s:HGroup>
    
        <s:CheckBox id="stateBox"
                    label="change state"
                    change="stateBox_changeHandler(event)"/>
    </s:WindowedApplication>
    

    Does this achieve the desired behavior ^ (sorry I know I changed a lot of code but this is just how I would approach it, maybe this won’t work because of other explicit sizing you need to set but seems to achieve the goal to me)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a window in WPF which shows some media contents. This content contains
I want to remove a particular tabpage from the tabcontrol. For which i have
I want to add a CComboBoxEx on my form, but I have to align
In my application I have a window which I popup with small messages on
I have a WPF Window which has a among other controls hosts a Frame.
I have a main window (#1) on my webpage from which I open a
I have a WPF window for editing database information, which is represented using an
I have a K* window, and within it, a widget which needs the events
I have a webapp which resizes its window to exactly fit its contents: window.resizeTo(200,300)
I have a page which spawns a popup browser window. I have a JavaScript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.