PDA

View Full Version : Anyone else seen this Accordion selectedIndex "oddity"?


CDHBookingEdge
11-05-2006, 12:51 PM
In trying to answer ljohnny18's post a bit ago I made the following quickie demo <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Alert;

private function OnViewChange() :void
{
if (accordion.selectedIndex == 1)
{
if (fldID.text.length == 0)
{
Alert.show("User ID has not been filled in.");
this.accordion.selectedIndex = 0;
}
else
{
Alert.show("Ok I'm in the Data View and I know my ID is " + this.fldID.text);
}
}
}
]]>
</mx:Script>
<mx:Panel title="Accordion Container Example"
height="90%" width="90%"
paddingTop="10" paddingLeft="10"
paddingRight="10" paddingBottom="10" layout="absolute">

<mx:Accordion id="accordion"
width="100%" height="100%" x="10" y="10"
change="OnViewChange();">
<!-- Define each panel using a VBox container. -->
<mx:VBox id="welcomeView" label="Welcome!" height="207" width="384">
<mx:Text text="Welcome to our Website. Please enter your ID before proceeding." fontFamily="Arial" fontSize="14" height="45" width="374" fontWeight="bold" textAlign="center"/>
<mx:Form backgroundColor="#ffffff">
<mx:FormItem label="User ID:">
<mx:TextInput id="fldID" editable="true" enabled="true"/>
</mx:FormItem>
</mx:Form>
</mx:VBox>

<mx:VBox id="dataView" label="View Data" height="210" width="381">
<mx:DataGrid width="376" height="197">
<mx:columns>
<mx:DataGridColumn headerText="Column 1" dataField="col1"/>
<mx:DataGridColumn headerText="Column 2" dataField="col2"/>
<mx:DataGridColumn headerText="Column 3" dataField="col3"/>
</mx:columns>
</mx:DataGrid>
</mx:VBox>

<mx:VBox id="contactView" label="Contact Us" width="385" height="206">
<mx:Text text="How to contact us" width="379" height="201"/>
</mx:VBox>
</mx:Accordion>

</mx:Panel>

</mx:Application>


Now this is the behaviour I'm seeing which I find a bit strange. When the user clicks from the first view to the second view with the ID not filled in, the message is displayed but they are not returned to the first view. But if the user is on the contact page (3rd view) and clicks on the 2nd view they DO get returned to the 1st page. Is this behaviour that you guys would expect based on the code? If so why? What did I miss?

Thanks in advance,
Christopher

ripvtech
11-07-2006, 04:09 PM
Chris,
Here is my solution


<mx:Script>
<![CDATA[
import mx.events.CloseEvent;
import mx.controls.Button;
import mx.controls.Alert;

private function OnViewChange() :void
{
if (accordion.selectedIndex == 1)
{
if (fldID.text.length == 0)
{
Alert.show("User ID has not been filled in.","none",Alert.OK,this,changeView);
}
else
{
Alert.show("Ok I'm in the Data View and I know my ID is " + this.fldID.text);
}
}
}
private function changeView(event:CloseEvent):void {
accordion.selectedIndex = 0;
}
]]>
</mx:Script>


From what I understand of this is in your original code when you got your popup box and then tried to set the selectedIndex back to 0 it was actually registered as being on the new Index yet. Therefore, it would "ignore" the command in a sense. That of course is just my opinion, and I am by no means anything more than a newbie. :-\

~JD

CDHBookingEdge
11-07-2006, 04:53 PM
opinion-schmapinion! LOL If it works and I'll try it out I'm sure it will if it did for you. Then that's the solution or at least one of many. ;-)

Also glad to see you got on the forum finally.

Christopher

ripvtech
11-12-2006, 12:02 AM
So did that work for you?

Yeah, I got on here, sorry for the comment in your blog asking to help, I was at a loss.

Thanks :)
~JD