August 30th, 2007 by Kyle
Tags: accordion, accordion-header, event, eventdispatcher, eventlistener, faking, faking-mouse-events, Flex, header, hover, mouse, mouse-event, mouse-events, mouseover
Posted in: Flex
I had a customer who asked for help in modifying the Accordion component to change panes when a user moused over a pane header rather than when clicked upon. It turns out that this was a fairly straight forward modification.
In my extension to accordion upon child add, I merely add an eventlistenr to each child’s header, listening for mouseOver events and responding to them by dispatching a click event. Everything else just fall into place, since things are already wired to respond to the click event.
Here is my extension to accordion:
<mx:accordion xmlns:mx="http://www.adobe.com/2006/mxml">
childAdd="onChildAdd(event)">
<mx:script>
<!–[CDATA[
import mx.containers.accordionClasses.AccordionHeader;
import mx.containers.Accordion;
private function onChildAdd(e:Event):void{
var a:Accordion = e.target as Accordion;
var header:AccordionHeader=a.getHeaderAt(acc.numChildren-1) as AccordionHeader;
header.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
}
private function onMouseOver(e:MouseEvent):void{
(e.target as AccordionHeader).dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
]]–>
</mx:script>
</mx:accordion>
Here is the simple app that demonstrates this functionality:
<mx:application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*">
<myaccordion id="accordion1" height="450">
<mx:form id="shippingAddress" label="1. Shipping Address">
<mx:formitem id="sfirstNameItem" label="First Name">
<mx:textinput id="sfirstName">
</mx:textinput>
<!– Additional contents goes here. –>
</mx:formitem>
<mx:form id="billingAddress" label="2. Billing Address">
<!– Form contents goes here. –>
</mx:form>
<mx:form id="creditCardInfo" label="3. Credit Card Information">
<!– Form contents goes here. –>
</mx:form>
<mx:form id="submitOrder" label="4. Submit Order">
<!– Form contents goes here. –>
</mx:form>
</mx:form>
</myaccordion>
</mx:application>
Here is a link to a Flex Builder 2.0.1 project (compiled with SDK hotfix2) containing a sample demonstrating the solution described above.
Tweet
3 Comments »

March 1st, 2008 at 9:33 pm
[...] Flexmonkeypatches [...]
June 9th, 2009 at 3:55 am
very cool thanks
March 16th, 2010 at 1:21 pm
Hi, thanks for this, I’ve been looking for that many hours.
There are few errors for me in flex 3 :
-> -> /2006/mxml”
(a.numChildren-1)
]]–> -> ]]>
->
->
7 errors, anyway, now it works… So THX