BTW,
You could put an else statement on that to throw() an error if you really
cared about the currentTarget not setting the style correctly.
I think this is the most elegantly decoupled way to attack the problem.
Peace, Mike
On 2/28/07, Michael Schmalle <[EMAIL PROTECTED]> wrote:
Or...
If you want to get really crazy and say what is the way you should do it
in perfection world, it would be;
if (event.currentTarget is IStyleClient)
IStyleClient(e.currentTarget).setStyle("color", "red");
Peace, Mike
On 2/28/07, Jamal Romero <[EMAIL PROTECTED]> wrote:
>
> Hi,
> Thanks for your reply. Yes that's what I wanted to
> say. The code will compile, I've tried it on
> www.flex.org online compiler and it did what expected
> without error. I think the compiler is not strict
> about type reference. But as has been said, it's
> better to type cast to the right ancestor or
> descendent an call the appropiate method. As coming
> from java land the java compiler won't tolerate this
> "error" if it is an error. When I get the target from
> the event it's not even a UIComponent, it's as been
> said an Object type. Anyway I'm still learning Flex.
> Java Swing id too slow, but I must say it wasn't a
> wast of time. It is a very elegant architecture but
> the problem is too slow. All the concept reading the
> Develp. Guide are familiar to me because they all
> implemented in Java Swing.
> Thanks
> Jairo
>
> --- Gordon Smith <[EMAIL PROTECTED] <gosmith%40adobe.com>> wrote:
>
> > The Developer's Guide is wrong... you won't get a
> > compilation error if
> > you don't cast. However, casting is best practice so
> > that the compiler
> > can help you catch coding mistakes. For example,
> >
> > e.currentTarget.setSytle(...)
> >
> > would compile despite the typo, but throw a runtime
> > error. However,
> >
> > Button(e.currentTarget).setSytle(...)
> >
> > would not compile.
> >
> > - Gordon
> >
> > ________________________________
> >
> > From: [email protected] <flexcoders%40yahoogroups.com>
> > [mailto:[email protected] <flexcoders%40yahoogroups.com>] On
> > Behalf Of Karl Johnson
> > Sent: Tuesday, February 27, 2007 10:27 AM
> > To: [email protected] <flexcoders%40yahoogroups.com>;
> > [email protected] <flexcoders%40yahoogroups.com>
> > Subject: RE: [flexcoders] Basic inheritance question
> >
> >
> >
> > In general you always want to cast something like
> > this - because
> > event.currentTarget is of type object and NOT
> > UIComponent or Button. But
> > since objects are loosely typed as type Object, then
> > you reference any
> > property or method you want at compile time. Often
> > at runtime though you
> > will hit errors unless it is properly casted. Your
> > sample application
> > was done in Flex 2 right?
> >
> > Definitely a best practice to be casting generic
> > objects like this to
> > the type of object you want to be working with to
> > avoid runtime errors
> >
> > Karl
> > Cynergy
> >
> > ________________________________
> >
> > From: [email protected] <flexcoders%40yahoogroups.com> on
> behalf of
> > jairokan
> > Sent: Tue 2/27/2007 11:53 AM
> > To: [email protected] <flexcoders%40yahoogroups.com>
> > Subject: [flexcoders] Basic inheritance question
> >
> >
> >
> > 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
> >
> >
> >
> >
> >
>
> __________________________________________________________
> Food fight? Enjoy some healthy debate
> in the Yahoo! Answers Food & Drink Q&A.
> http://answers.yahoo.com/dir/?link=list&sid=396545367
>
>
>
--
Teoti Graphix
http://www.teotigraphix.com
Blog - Flex2Components
http://www.flex2components.com
You can find more by solving the problem then by 'asking the question'.
--
Teoti Graphix
http://www.teotigraphix.com
Blog - Flex2Components
http://www.flex2components.com
You can find more by solving the problem then by 'asking the question'.