I think I'll use this, it certainly can help hacking this bug, but I
can't believe this bug hasn't been talked before, maybe there is less
hacky way to deal with it ?

Anyway, that really helps me, thank you !

Cheers,
Almog Kurtser


--- In flexcoders@yahoogroups.com, "rueter007" <[EMAIL PROTECTED]> wrote:
>
> I uncommented that line from your code before and did see the error.
> And I agree that there are two event listeners now. If all you want to
> do is replace the old event listener with a new one, you can still
> listen for a state change event and in the event handler, manually
> remove the old listener and add the new event listener.
> 
> this.addEventListener(StateChangeEvent.CURRENT_STATE_CHANGE,
> handleStateChange);
> 
> in the handleStateChange, you can check what the new state is and
> add/remove event listeners accordingly.
> 
> --- In flexcoders@yahoogroups.com, "mydarkspoon" <mydarkspoon@> wrote:
> >
> > Hi,
> > first of all, thanks for the reply, I had a piece of my main app code
> > commented, so if you just copied and paste it, you won't see the bug
> > immediately, sorry, the fixed code is bellow.
> > 
> > I tried to use actionscript addEventListener, yet, the problem with
> > this approach is that SetEventHandlet purpose is to replace the
> > handling function, however, it won't unregister actionscript event
> > listeners, so the error won't show up but now we'll have 2 listeners
> > instead of 1.
> >  
> > The good code (still with the bug):
> > 
> > <?xml version="1.0" encoding="utf-8"?>
> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> > layout="absolute" xmlns:local="*" creationComplete="init()">
> >     <mx:Script>
> >             <![CDATA[
> >                     import mx.controls.Alert;
> >                     
> >                     private function onClick1(evt:Event):void
> >                     {
> >                             Alert.show("chnaging from state 1 to state 2");
> >                             currentState = "myState"
> >                     }
> >                     
> >                     private function onClick2():void
> >                     {
> >                             Alert.show("state 2");
> >                     }
> >             ]]>
> >     </mx:Script>
> >     
> >     <mx:states>
> >             <mx:State name="myState">
> >                     <mx:SetEventHandler target="{bt}" handler="onClick2()"
> > name="goPrevious" />
> >             </mx:State>
> >     </mx:states>
> >     <local:MyButton id="bt" goPrevious="onClick1(event)" />
> > </mx:Application>
> > 
> > 
> > Thanks a lot,
> > 
> > Almog Kurtser
> > 
> > 
> > 
> > 
> > --- In flexcoders@yahoogroups.com, "rueter007" <rueter007@> wrote:
> > >
> > > Hey,
> > > 
> > > I ran your code and I could reproduce the error you got. It
seems like
> > > a bug in the SetEventHandler code. However, if you add the initial
> > > event listener in actionscript, it all works fine.
> > > 
> > >   private function init():void
> > >   {
> > >           trace(document.toString());
> > >           bt.addEventListener("change", onClick1);
> > >   }
> > > 
> > > - venkat
> > > http://www.venkatj.com
> > > 
> > > 
> > > --- In flexcoders@yahoogroups.com, "mydarkspoon" <mydarkspoon@>
wrote:
> > > >
> > > > Hi,
> > > > 
> > > > I encountered an error using the SetEventHandler and made a simple
> > > > test case to see what was the problem:
> > > > In my app I have a component that contains button and dispatches a
> > > > "goPrevious" event when the component::button is clicked.
> > > > Following the "goPrevious" event, the main app changes its
> state.  The
> > > > new state uses the SetEventHandler to change the
> "goPreviousHandler":
> > > > 
> > > > My main app:
> > > > <?xml version="1.0" encoding="utf-8"?>
> > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> > > > layout="absolute" xmlns:local="*" creationComplete="init()">
> > > >         <mx:Script>
> > > >                 <![CDATA[
> > > >                         import mx.controls.Alert;
> > > >                         
> > > >                         private function init():void
> > > >                         {
> > > >                                 trace(document.toString());
> > > >                         }
> > > >                         private function onClick1(evt:Event):void
> > > >                         {
> > > >                                 Alert.show("chnaging from state 1 to 
> > > > state 2");
> > > >                                 currentState = "myState"
> > > >                         }
> > > >                         
> > > >                         private function onClick2(evt:Event):void
> > > >                         {
> > > >                                 Alert.show("state 2");
> > > >                         }
> > > >                 ]]>
> > > >         </mx:Script>
> > > >         
> > > >         <mx:states>
> > > >                 <mx:State name="myState">
> > > >                         <mx:SetProperty target="{bt}" name="alpha" 
> > > > value="0.2" /
> > > >                         <!--<mx:SetEventHandler target="{bt}"
handlerFunction="onClick2"
> > > > name="goPrevious" /> -->
> > > >                 </mx:State>
> > > >         </mx:states>
> > > >         <local:MyButton id="bt" goPrevious="onClick1(event)" />
> > > >         <!--<mx:Button id="bt" click="onClick1()"  /> -->
> > > > </mx:Application>
> > > > 
> > > > ---------------------------------------------------------------
> > > > The Component:
> > > > 
> > > > <?xml version="1.0" encoding="utf-8"?>
> > > > <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"; width="100"
> > > > height="100" 
> > > >         click="onClick()" creationPolicy="auto" >
> > > > <mx:Metadata>
> > > >         [Event(name="goPrevious", type="events.NavigationEvent")]
> > > > </mx:Metadata>
> > > > 
> > > > <mx:Script>
> > > >         <![CDATA[
> > > >                 import events.NavigationEvent;
> > > >                 
> > > >                 private function onClick():void
> > > >                 {
> > > >                         dispatchEvent(new
NavigationEvent(NavigationEvent.GO_PREVIOUS));
> > > >                 }
> > > >         ]]>
> > > > </mx:Script>
> > > >         <mx:Button label="previous" click="onClick()" />
> > > > </mx:VBox>
> > > > 
> > > > 
> > > > 
> > > > And this is the error you get from the SetEventH/handler object:
> > > > 
> > > > ReferenceError: Error #1069: Property __bt_goPrevious not found on
> > > > MyButton and there is no default value.
> > > >         at mx.states::SetEventHandler/apply()
> > > > 
> > > > 
> > > > It seems that inside the SetEventHandler.apply() function it can't
> > > > find the oldHandlerFunction.
> > > > 
> > > > 
> > > > I'm struggling this bug for hours now and been goggling it a
> lot, yet
> > > > nothing useful was found...
> > > > 
> > > > I'd be grateful if anyone take a look at that.
> > > > 
> > > > Thanks in advance, 
> > > > Almog Kurtser
> > > >
> > >
> >
>


Reply via email to