<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Programmatically changing a Flex Accordion container&#8217;s selected index</title>
	<link>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/</link>
	<description>A bunch of examples for Adobe Flex and ActionScript</description>
	<pubDate>Mon, 13 Oct 2008 08:51:17 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>

	<item>
		<title>By: Scooter</title>
		<link>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-14898</link>
		<author>Scooter</author>
		<pubDate>Sun, 24 Aug 2008 14:19:16 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-14898</guid>
		<description>After fighting with this for quite a while, I came across an interesting way to do this.  The code below is not exactly what I am using (my project is a little more complicated than this) but this should give you the basic idea.  If the requirement is not met I first store the value of the step to return to and then add an event handler to the accordion for the &lt;code&gt;FlexEvent.UPDATE_COMPLETE&lt;/code&gt; event.  The handler is called after the event completes.  Then we set the accordion &lt;code&gt;selectedIndex&lt;/code&gt; back to the stored value we saved earlier and finally we remove the event handler we added.  You still see the accordion slide down and then back up and then see the alert.  Kind of cool I guess.
&lt;pre class="code"&gt;
private function myAccordion(e:IndexChangedEvent):void {
  // perform validations before allowing step change
  if (e.newIndex &#62; 0) {
    // selection required to move beyond this step
    if (myRequiredItem== null) {
      // save the step to return to
      this.current_step = 0;      
      // add the event listener
      myAccordion.addEventListener(FlexEvent.UPDATE_COMPLETE, flexUpdateComplete);
      // show an alert - this won't show until the slide is complete actually
      Alert.show("You must select a fabric!");
    }
  }
}

private function flexUpdateComplete(event:Object):void {
  myAccordion.selectedIndex = this.current_step;
  myAccordion.removeEventListener(FlexEvent.UPDATE_COMPLETE, flexUpdateComplete);
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>After fighting with this for quite a while, I came across an interesting way to do this.  The code below is not exactly what I am using (my project is a little more complicated than this) but this should give you the basic idea.  If the requirement is not met I first store the value of the step to return to and then add an event handler to the accordion for the <code>FlexEvent.UPDATE_COMPLETE</code> event.  The handler is called after the event completes.  Then we set the accordion <code>selectedIndex</code> back to the stored value we saved earlier and finally we remove the event handler we added.  You still see the accordion slide down and then back up and then see the alert.  Kind of cool I guess.</p>
<pre class="code">
private function myAccordion(e:IndexChangedEvent):void {
  // perform validations before allowing step change
  if (e.newIndex &gt; 0) {
    // selection required to move beyond this step
    if (myRequiredItem== null) {
      // save the step to return to
      this.current_step = 0;
      // add the event listener
      myAccordion.addEventListener(FlexEvent.UPDATE_COMPLETE, flexUpdateComplete);
      // show an alert - this won't show until the slide is complete actually
      Alert.show("You must select a fabric!");
    }
  }
}

private function flexUpdateComplete(event:Object):void {
  myAccordion.selectedIndex = this.current_step;
  myAccordion.removeEventListener(FlexEvent.UPDATE_COMPLETE, flexUpdateComplete);
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scooter</title>
		<link>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-14897</link>
		<author>Scooter</author>
		<pubDate>Sun, 24 Aug 2008 14:04:07 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-14897</guid>
		<description>After fighting with trying to stop this event to make a user fill in a required vale before moving to another step I found an interesting way to accomplish it:
&lt;pre class="code"&gt;
private function accBuildSteps_test(e:IndexChangedEvent):void {
    // perform validations before allowing step change
    if (e.newIndex &#62; 0) {
        // selection required to move beyond this step
        if (mgrProducts.SelectedFabric == null) {
            accBuildSteps.addEventListener(FlexEvent.UPDATE_COMPLETE, flexUpdateComplete);
            Alert.show("You must select a fabric!");
        }
    }
}

private function flexUpdateComplete(event:Object):void {
    accBuildSteps.selectedIndex = 0;
    accBuildSteps.removeEventListener(FlexEvent.UPDATE_COMPLETE, flexUpdateComplete);
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>After fighting with trying to stop this event to make a user fill in a required vale before moving to another step I found an interesting way to accomplish it:</p>
<pre class="code">
private function accBuildSteps_test(e:IndexChangedEvent):void {
    // perform validations before allowing step change
    if (e.newIndex &gt; 0) {
        // selection required to move beyond this step
        if (mgrProducts.SelectedFabric == null) {
            accBuildSteps.addEventListener(FlexEvent.UPDATE_COMPLETE, flexUpdateComplete);
            Alert.show("You must select a fabric!");
        }
    }
}

private function flexUpdateComplete(event:Object):void {
    accBuildSteps.selectedIndex = 0;
    accBuildSteps.removeEventListener(FlexEvent.UPDATE_COMPLETE, flexUpdateComplete);
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-13139</link>
		<author>peterd</author>
		<pubDate>Sat, 31 May 2008 06:43:17 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-13139</guid>
		<description>For another example (with SWFs), see &lt;a href="http://blog.flexexamples.com/2008/05/30/preventing-users-from-clicking-on-an-accordion-containers-header-in-flex/" rel="nofollow"&gt;&lt;u&gt;"Preventing users from clicking on an Accordion container's header in Flex"&lt;/u&gt;&lt;/a&gt;.

Peter</description>
		<content:encoded><![CDATA[<p>For another example (with SWFs), see <a href="http://blog.flexexamples.com/2008/05/30/preventing-users-from-clicking-on-an-accordion-containers-header-in-flex/" rel="nofollow"><u>&#8220;Preventing users from clicking on an Accordion container&#8217;s header in Flex&#8221;</u></a>.</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-13127</link>
		<author>peterd</author>
		<pubDate>Sat, 31 May 2008 00:35:42 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-13127</guid>
		<description>Nick,

Actually, &lt;em&gt;this&lt;/em&gt; may be a better way of doing what you want (or, at least I think it is cool):
&lt;pre class="code"&gt;
&#60;?xml version="1.0" encoding="utf-8"?&#62;
&#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&#62;

    &#60;mx:Accordion id="acc"
            headerRenderer="comps.MyAccHeader"
            width="100%" height="100%"&#62;
        &#60;mx:VBox id="v1" label="One"&#62;
            
        &#60;/mx:VBox&#62;
        &#60;mx:VBox id="v2" label="Two" enabled="false"&#62;
            
        &#60;/mx:VBox&#62;
        &#60;mx:VBox id="v3" label="Three" enabled="false"&#62;
            
        &#60;/mx:VBox&#62;
        &#60;mx:VBox id="v4" label="Four"&#62;
            
        &#60;/mx:VBox&#62;
        &#60;mx:VBox id="v5" label="Five"&#62;
            
        &#60;/mx:VBox&#62;
    &#60;/mx:Accordion&#62;
    
&#60;/mx:Application&#62;
&lt;/pre&gt;

&lt;strong&gt;comps/MyAccHeader.as&lt;/strong&gt;
&lt;pre class="code"&gt;
package comps {
    import mx.containers.accordionClasses.AccordionHeader;
    import mx.events.FlexEvent;

    public class MyAccHeader extends AccordionHeader {
        public function MyAccHeader() {
            super();
            addEventListener(FlexEvent.INITIALIZE, accordionHeader_initialize);
        }

        private function accordionHeader_initialize(evt:FlexEvent):void {
            enabled = data.enabled;
        }
    }
}
&lt;/pre&gt;

Now the &lt;code&gt;enabled&lt;/code&gt; property on the VBox container should bubble up to the AccordionHeader.

In fact, I think it is &lt;em&gt;SO&lt;/em&gt; cool and useful that I may turn it into today's "official" 
example (and that way it will get a nice SWF too).

Happy Flexing!
Peter</description>
		<content:encoded><![CDATA[<p>Nick,</p>
<p>Actually, <em>this</em> may be a better way of doing what you want (or, at least I think it is cool):</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Accordion id="acc"
            headerRenderer="comps.MyAccHeader"
            width="100%" height="100%"&gt;
        &lt;mx:VBox id="v1" label="One"&gt;

        &lt;/mx:VBox&gt;
        &lt;mx:VBox id="v2" label="Two" enabled="false"&gt;

        &lt;/mx:VBox&gt;
        &lt;mx:VBox id="v3" label="Three" enabled="false"&gt;

        &lt;/mx:VBox&gt;
        &lt;mx:VBox id="v4" label="Four"&gt;

        &lt;/mx:VBox&gt;
        &lt;mx:VBox id="v5" label="Five"&gt;

        &lt;/mx:VBox&gt;
    &lt;/mx:Accordion&gt;

&lt;/mx:Application&gt;
</pre>
<p><strong>comps/MyAccHeader.as</strong></p>
<pre class="code">
package comps {
    import mx.containers.accordionClasses.AccordionHeader;
    import mx.events.FlexEvent;

    public class MyAccHeader extends AccordionHeader {
        public function MyAccHeader() {
            super();
            addEventListener(FlexEvent.INITIALIZE, accordionHeader_initialize);
        }

        private function accordionHeader_initialize(evt:FlexEvent):void {
            enabled = data.enabled;
        }
    }
}
</pre>
<p>Now the <code>enabled</code> property on the VBox container should bubble up to the AccordionHeader.</p>
<p>In fact, I think it is <em>SO</em> cool and useful that I may turn it into today&#8217;s &#8220;official&#8221;<br />
example (and that way it will get a nice SWF too).</p>
<p>Happy Flexing!<br />
Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick</title>
		<link>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-13126</link>
		<author>Nick</author>
		<pubDate>Fri, 30 May 2008 23:35:14 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-13126</guid>
		<description>Peter! Thank you sooooooooooooooooo much. Your first reply did the trick EXACTLY what I was looking for! 

OMG TY TY TY

- Nick</description>
		<content:encoded><![CDATA[<p>Peter! Thank you sooooooooooooooooo much. Your first reply did the trick EXACTLY what I was looking for! </p>
<p>OMG TY TY TY</p>
<p>- Nick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-13125</link>
		<author>peterd</author>
		<pubDate>Fri, 30 May 2008 21:52:59 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-13125</guid>
		<description>As for disabling individual Accordion headers, this ActionScript should work:
&lt;pre class="code"&gt;
acc.getHeaderAt(0).enabled = false;
&lt;/pre&gt;

Peter</description>
		<content:encoded><![CDATA[<p>As for disabling individual Accordion headers, this ActionScript should work:</p>
<pre class="code">
acc.getHeaderAt(0).enabled = false;
</pre>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peterd</title>
		<link>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-13124</link>
		<author>peterd</author>
		<pubDate>Fri, 30 May 2008 21:11:02 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-13124</guid>
		<description>&lt;a href="http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-12581" rel="nofollow"&gt;Keith&lt;/a&gt; and &lt;a href="http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-13121" rel="nofollow"&gt;Nick&lt;/a&gt;,

This should disable all Accordion header mouse clicks and only allow users to change the selected child using the nested Button controls. (I say *should* since I haven't really tested this):

&lt;pre class="code"&gt;
&#60;?xml version="1.0" encoding="utf-8"?&#62;
&#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&#62;

    &#60;mx:Accordion id="acc"
            headerRenderer="comps.MyAccHeader"
            width="100%" height="100%"&#62;
        &#60;mx:VBox id="v1" label="One"&#62;
            &#60;mx:Button label="next" click="acc.selectedChild = v2;" /&#62;
        &#60;/mx:VBox&#62;
        &#60;mx:VBox id="v2" label="Two"&#62;
            &#60;mx:Button label="prev" click="acc.selectedChild = v1;" /&#62;
            &#60;mx:Button label="next" click="acc.selectedChild = v3;" /&#62;
        &#60;/mx:VBox&#62;
        &#60;mx:VBox id="v3" label="Three"&#62;
            &#60;mx:Button label="prev" click="acc.selectedChild = v2;" /&#62;
            &#60;mx:Button label="next" click="acc.selectedChild = v4;" /&#62;
        &#60;/mx:VBox&#62;
        &#60;mx:VBox id="v4" label="Four"&#62;
            &#60;mx:Button label="prev" click="acc.selectedChild = v3;" /&#62;
            &#60;mx:Button label="next" click="acc.selectedChild = v5;" /&#62;
        &#60;/mx:VBox&#62;
        &#60;mx:VBox id="v5" label="Five"&#62;
            &#60;mx:Button label="prev" click="acc.selectedChild = v4;" /&#62;
        &#60;/mx:VBox&#62;
    &#60;/mx:Accordion&#62;
    
&#60;/mx:Application&#62;
&lt;/pre&gt;

&lt;strong&gt;comps/MyAccHeader.as&lt;/strong&gt;
&lt;pre class="code"&gt;
package comps {
    import mx.containers.accordionClasses.AccordionHeader;

    public class MyAccHeader extends AccordionHeader {
        public function MyAccHeader() {
            super();
            mouseEnabled = false;
        }    
    }
}
&lt;/pre&gt;

And there may be better ways of doing this, but this was the first thing that came to mind.

Hope that helps,
Peter</description>
		<content:encoded><![CDATA[<p><a href="http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-12581" rel="nofollow">Keith</a> and <a href="http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-13121" rel="nofollow">Nick</a>,</p>
<p>This should disable all Accordion header mouse clicks and only allow users to change the selected child using the nested Button controls. (I say *should* since I haven&#8217;t really tested this):</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Accordion id="acc"
            headerRenderer="comps.MyAccHeader"
            width="100%" height="100%"&gt;
        &lt;mx:VBox id="v1" label="One"&gt;
            &lt;mx:Button label="next" click="acc.selectedChild = v2;" /&gt;
        &lt;/mx:VBox&gt;
        &lt;mx:VBox id="v2" label="Two"&gt;
            &lt;mx:Button label="prev" click="acc.selectedChild = v1;" /&gt;
            &lt;mx:Button label="next" click="acc.selectedChild = v3;" /&gt;
        &lt;/mx:VBox&gt;
        &lt;mx:VBox id="v3" label="Three"&gt;
            &lt;mx:Button label="prev" click="acc.selectedChild = v2;" /&gt;
            &lt;mx:Button label="next" click="acc.selectedChild = v4;" /&gt;
        &lt;/mx:VBox&gt;
        &lt;mx:VBox id="v4" label="Four"&gt;
            &lt;mx:Button label="prev" click="acc.selectedChild = v3;" /&gt;
            &lt;mx:Button label="next" click="acc.selectedChild = v5;" /&gt;
        &lt;/mx:VBox&gt;
        &lt;mx:VBox id="v5" label="Five"&gt;
            &lt;mx:Button label="prev" click="acc.selectedChild = v4;" /&gt;
        &lt;/mx:VBox&gt;
    &lt;/mx:Accordion&gt;

&lt;/mx:Application&gt;
</pre>
<p><strong>comps/MyAccHeader.as</strong></p>
<pre class="code">
package comps {
    import mx.containers.accordionClasses.AccordionHeader;

    public class MyAccHeader extends AccordionHeader {
        public function MyAccHeader() {
            super();
            mouseEnabled = false;
        }
    }
}
</pre>
<p>And there may be better ways of doing this, but this was the first thing that came to mind.</p>
<p>Hope that helps,<br />
Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick</title>
		<link>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-13121</link>
		<author>Nick</author>
		<pubDate>Fri, 30 May 2008 17:52:01 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-13121</guid>
		<description>Hey Peter,

I'm in the same boat as Rod Keith also lol. Can you possibly do a example on how to disable accordion index's not allowing the user to click them to bring them up but rather click a continue or submit button in the main accordion index which loads you into the next accordion index?

Please :)

- Nick</description>
		<content:encoded><![CDATA[<p>Hey Peter,</p>
<p>I&#8217;m in the same boat as Rod Keith also lol. Can you possibly do a example on how to disable accordion index&#8217;s not allowing the user to click them to bring them up but rather click a continue or submit button in the main accordion index which loads you into the next accordion index?</p>
<p>Please :)</p>
<p>- Nick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith</title>
		<link>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-12581</link>
		<author>Keith</author>
		<pubDate>Fri, 09 May 2008 13:53:07 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-12581</guid>
		<description>I am in the same boat as Rod.  I want to catch the change event and cancel the accordion slide if certain criteria have not been met.  Any ideas?</description>
		<content:encoded><![CDATA[<p>I am in the same boat as Rod.  I want to catch the change event and cancel the accordion slide if certain criteria have not been met.  Any ideas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rod</title>
		<link>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-8069</link>
		<author>Rod</author>
		<pubDate>Wed, 26 Mar 2008 18:01:32 +0000</pubDate>
		<guid>http://blog.flexexamples.com/2007/09/17/programmatically-changing-a-flex-accordion-containers-selected-index/#comment-8069</guid>
		<description>Nevermind, I got it working by referencing your &lt;code&gt;getHeaderAt()&lt;/code&gt; example:
&lt;pre class="code"&gt;
Accordion.getHeaderAt(1).enabled = false;
&lt;/pre&gt;

I'd like to know if there are others ways to do the same thing, but this will work for me.

regards,
-r</description>
		<content:encoded><![CDATA[<p>Nevermind, I got it working by referencing your <code>getHeaderAt()</code> example:</p>
<pre class="code">
Accordion.getHeaderAt(1).enabled = false;
</pre>
<p>I&#8217;d like to know if there are others ways to do the same thing, but this will work for me.</p>
<p>regards,<br />
-r</p>
]]></content:encoded>
	</item>
</channel>
</rss>
