The docs are telling you that event.currentTarget is typed to
DisplayObject, which is higher in the inheritance chain that
UIComponent. So to use setStyle you've got to type-cast
event.currentTarget to either UIComponent, or some type below
UIComponent in the inheritance chain. So typecasting to Button would
work fine as well, but you can't not typecast it and expect to get
access to setStyle, or other methods of UIComponent.

So either:
UIComponent(e.currentTarget).setStyle("color", "red");

or:
Button(e.currentTarget).setStyle("color", "red");

would work fine, but simply:
e.currentTarget.setStyle("color", "red");

wouldn't.

Doug

On 2/27/07, jairokan <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
>
>
>
> Hi,
> I'm reading the Developer's Guide and in the section using Events, they say 
> on a paragraph that :
> "If you try to call another method on the currentTarget (for example, the 
> setStyle() method), Flex returns an error. The setStyle() method is defined 
> on UIComponent, a subclass of DisplayObject. Therefore, you must cast 
> currentTarget to UIComponent before calling the setStyle() method"
> for example:
> <mx:Script>
> <![CDATA[
>      import mx.core.UIComponent;
>
>      private function myEventHandler(e:Event):void {
>         UIComponent(e.currentTarget).setStyle("color", "red");
>      }
>   ]]>
> </mx:Script>
>
> and e.currentTarget is of type Button. But Button extends UIComponent, so we 
> don't have to upcast the reference because setStyle method is public and is 
> available to Button object reference0. I tried the code without upcasting and 
> it works.
> Is the writer wrong or Am I missing something on the concept.
>
> Thanks
>
> Jairo
>
>
>
>                   

Reply via email to