2 Replies Latest reply on Apr 29, 2010 2:49 PM by JHWH_BBB

    setElementIndex and Changing State problem

    JHWH_BBB

      I am having issues with elements disappearing after calling the setElementIndex method and then changing states,  below is sample code of the error.

       

      The idea is to have each button come to the top of the display list when it is clicked, so that it does not appear underneath any other buttons.  I'm not sure if I'm doing it the correct way, so any tips would be much appreciated

       

      With the example below, change to State2 click on a few buttons, then change back to State 1.

       

       

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

      <s:Application 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="1024" minHeight="768" currentState="State1">

       

      <fx:Script>

      <![CDATA[

      protected function button1_mouseDownHandler(event:MouseEvent):void

      {

      var b:Button = event.target as Button;

      holder.setElementIndex(b, holder.numElements - 1);

      }

      ]]>

      </fx:Script>

       

      <s:states>

      <s:State name="State1"/>

      <s:State name="State2"/>

      </s:states>

       

      <s:Group id="holder">

      <s:Button label="Button" width.State2="40" height.State2="40" mouseDown="button1_mouseDownHandler(event)" x.State1="161" y.State1="9" x.State2="161" y.State2="6"/>

      <s:Button label="Button" width.State2="40" height.State2="40" mouseDown="button1_mouseDownHandler(event)" x.State1="164" y.State1="137" x.State2="164" y.State2="134"/>

      <s:Button label="Button" width.State2="40" height.State2="40" mouseDown="button1_mouseDownHandler(event)" x.State1="163" y.State1="104" x.State2="163" y.State2="101"/>

      <s:Button label="Button" width.State2="40" height.State2="40" mouseDown="button1_mouseDownHandler(event)" x.State1="162" y.State1="71" x.State2="162" y.State2="68"/>

      <s:Button label="Button" width.State2="40" height.State2="40" mouseDown="button1_mouseDownHandler(event)" x.State1="161" y.State1="38" x.State2="161" y.State2="35"/>

      <s:Button label="Button" width.State2="40" height.State2="40" mouseDown="button1_mouseDownHandler(event)" x.State1="5" y.State1="38" x.State2="5" y.State2="35"/>

      <s:Button label="Button" width.State2="40" height.State2="40" mouseDown="button1_mouseDownHandler(event)" x.State1="83" y.State1="38" x.State2="83" y.State2="35"/>

      <s:Button label="Button" width.State2="40" height.State2="40" mouseDown="button1_mouseDownHandler(event)" x.State2="5" x.State1="5" y.State1="9" y.State2="6"/>

      <s:Button label="Button" width.State2="40" height.State2="40" mouseDown="button1_mouseDownHandler(event)" x.State1="83" y.State1="9" x.State2="83" y.State2="6"/>

      <s:Button label="Button" width.State2="40" height.State2="40" mouseDown="button1_mouseDownHandler(event)" x.State1="8" y.State1="137" x.State2="8" y.State2="134"/>

      <s:Button label="Button" width="40" height="40" mouseDown="button1_mouseDownHandler(event)" includeIn="State2" x="85" y="134"/>

      <s:Button label="Button" width.State2="40" height.State2="40" mouseDown="button1_mouseDownHandler(event)" x.State1="7" y.State1="104" x.State2="7" y.State2="101"/>

      <s:Button label="Button" width.State2="40" height.State2="40" mouseDown="button1_mouseDownHandler(event)" x.State1="85" y.State1="104" x.State2="85" y.State2="101"/>

      <s:Button label="Button" width.State2="40" height.State2="40" mouseDown="button1_mouseDownHandler(event)" x.State1="6" y.State1="71" x.State2="6" y.State2="68"/>

      <s:Button label="Button" width="40" height="40" mouseDown="button1_mouseDownHandler(event)" includeIn="State2" x="82" y="68"/>

      </s:Group>

      <s:Button label="Change State" click.State2="currentState='State1'" click.State1="currentState='State2'" x.State2="50" y.State2="208" x.State1="71" y.State1="192"/>

      </s:Application>

        • 1. Re: setElementIndex and Changing State problem
          Shongrunden Adobe Employee

          This looks like a bug. Here is a simplified test case:

          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                         xmlns:s="library://ns.adobe.com/flex/spark">

           

              <s:states>
                  <s:State name="state1"/>
                  <s:State name="state2"/>
              </s:states>

           

              <s:controlBarContent>
                  <s:Button label="Change State" click="currentState=currentState=='state1'?'state2':'state1'" />
              </s:controlBarContent>

           

              <s:Group id="group1">
                  <s:Button id="btn1" label="1" click="group1.setElementIndex(btn1, 1)" x="50" y="50"/>
                  <s:Button id="btn2" label="2" includeIn="state2" x="65" y="65" />
              </s:Group>
             
          </s:Application>

           

          Instructions to reproduce:

           

          1. Click "Change State" button

          2. Click the "1" button to bring it to the front

          3. Click "Change state"

          4. Click "Change state" again

          5. Notice that button 1 disappears.

           

          Can you please file a bug and post the link to it here?  Let me know if not and I'll file it for you.

          1 person found this helpful
          • 2. Re: setElementIndex and Changing State problem
            JHWH_BBB Level 1

            Thank you for looking into this,

             

            bug created here - http://bugs.adobe.com/jira/browse/SDK-26342