2 Replies Latest reply on Apr 23, 2007 7:01 AM by adjunkt

    Newbie Transition Bug

    adjunkt
      Hi.. Im having a Transition Bug:

      The intended effect is that the page fades in from nothing.

      It works when triggred by the button, but when triggered by the combo the new page instantly appears, THEN vanishes, THEN fades in from nothing as intended:

      Sorry about the awful code. The application has no point. It is just buttons and features thrown together to learn about FLEX

      I have used bold to indicate the relevant code.

      -----------------------

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application
      xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="absolute"
      initialize="initData();">


      <mx:Script>
      <![CDATA[
      import mx.utils.ArrayUtil;
      public var currentPage:String="start";
      ]]>
      </mx:Script>

      <mx:Model id="bookModel" source="assets/myData.xml"/>

      <mx:ArrayCollection id="pageArray"
      source="{ArrayUtil.toArray(bookModel.page)}"
      />

      <mx:Script>
      <![CDATA[
      //import mx.collections.ArrayCollection;
      import mx.collections.ICollectionView;
      import mx.collections.IViewCursor;
      import mx.collections.SortField;
      import mx.collections.Sort;

      public var myCursor:IViewCursor;
      public var myArray:Array;
      public var myArrayCollection:ArrayCollection;

      public function gotoPage(pageId:String):void
      {
      myCursor=pageArray.createCursor();
      myCursor.findAny({id:pageId});
      textPageBody.text = myCursor.current.body;
      //var value:String;
      //value = myCursor.current.id;
      myArray=ArrayUtil.toArray(myCursor.current.choice);
      myArrayCollection = new ArrayCollection(myArray);
      dataChoice.dataProvider = myArrayCollection;
      }

      public function gotoCurrentPage():void
      {
      var currentPage:String;
      currentPage=dataChoice.selectedItem.goto;
      gotoPage(currentPage);
      }

      public function changePageState():void
      {
      currentState=comboPageState.value.toString();
      }

      public function initData():void
      {
      var sort:Sort = new Sort();
      sort.fields = [new SortField("id", true)];
      pageArray.sort = sort;
      pageArray.refresh();
      gotoPage('1');
      }
      ]]>
      </mx:Script>

      <mx:states>
      <mx:State name="helpState">
      <mx:SetProperty target="{panelMain}" name="width" value="350"/>
      <mx:SetProperty target="{panelMain}" name="title" value="Help Page"/>
      <mx:SetProperty target="{panelMain}" name="height" value="350"/>
      <mx:AddChild relativeTo="{panelMain}" position="lastChild">
      <mx:DataGrid x="10" y="132" height="88" width="310"
      dataProvider="{pageArray}">
      <mx:columns>
      <mx:DataGridColumn headerText="ID" dataField="id"/>
      <mx:DataGridColumn headerText="BODY" dataField="body"/>
      </mx:columns>
      </mx:DataGrid>
      </mx:AddChild>
      <mx:SetProperty target="{dataChoice}" name="height" value="72"/>
      <mx:SetProperty target="{dataChoice}" name="y" value="228"/>
      <mx:SetProperty target="{textPageBody}" name="height" value="43"/>
      <mx:SetProperty target="{txtAnswer}" name="y" value="97"/>
      <mx:SetProperty target="{txtAnswer}" name="height" value="27"/>
      </mx:State>
      </mx:states>
      <mx:transitions>
      <mx:Transition id="myTransition" fromState="*" toState="helpState">
      <mx:Dissolve target="{panelMain}" alphaFrom="0.0" alphaTo="1.0" duration="2000"/>
      </mx:Transition>


      </mx:transitions>


      <mx:Panel x="10" y="10" width="350" height="350" layout="absolute" title="my application" cornerRadius="12" id="panelMain">
      <mx:TextArea y="46" text="不用谢" fontSize="17" height="62" left="10" right="60" id="textPageBody"/>
      <mx:Button x="288" y="278" label="不" id="btnCharacter"/>
      <mx:TextArea x="10" y="111" width="310" id="txtAnswer"/>
      <mx:DataGrid x="10" y="158" width="250" id="dataChoice" change="gotoCurrentPage()">
      <mx:columns>
      <mx:DataGridColumn headerText="CHOICES" dataField="text"/>
      <mx:DataGridColumn headerText="GOTO" dataField="goto"/>
      </mx:columns>
      </mx:DataGrid>
      <mx:ComboBox x="10" y="14" change="changePageState()" id="comboPageState">
      <mx:dataProvider>
      <mx:Array>
      <mx:Object label="Standard" data=""/>
      <mx:Object label="Help" data="helpState"/>
      <mx:Object label="Statistics" data="statisticsState"/>
      </mx:Array>
      </mx:dataProvider>
      </mx:ComboBox>
      <mx:Button x="255" y="14" label="HELP!" click="currentState=&quot;helpState&quot;"/>
      </mx:Panel>

      </mx:Application>
        • 1. Newbie Transition Bug
          QuickStick Level 1
          Howdy,

          Try changing the event change="changePageState()" from "change" to "valueCommit" or something like that: valueCommit="changePageState()".

          The problem is that Flex is updating the data before running the transition. You need to get it to run the transition before changing the data.

          If that doesn't fix it, could you post the XML data as per assets/myData.xml - sorry, I was having some trouble, because it kept giving errors without the XML.

          Hope that helps.
          Cheers
          Oz.
          • 2. Re: Newbie Transition Bug
            adjunkt Level 1
            SOLVED! thanks!

            (And thanks for going as far as trying to run it too)