Was this a compilation error or a runtime error? It sounds like you were
trying to call a private method, selectPlayer(), from another class. It
doesn't sound like the error had anything to do with testing whether
LAST_SELECTED was null or not. You didn't show any code that actually
called selectPlayer().
 
- Gordon

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of [EMAIL PROTECTED]
Sent: Monday, April 23, 2007 11:26 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Testing if a datatyped variable is not set yet



This was the error I got

1195: Attempted access of inaccessible method selectPlayer through a
reference with static type khGame:Player.

--Keith H--

> You didn't say what error you're getting when you compare with null 
> (?)
> On 4/23/07, [EMAIL PROTECTED] <mailto:khair%40nc.rr.com>
<[EMAIL PROTECTED] <mailto:khair%40nc.rr.com> > wrote:
> > I have a class, "Player" that with a "selectPlayer" method.
> > I want "selectPlayer" to automatically deselect the last selected 
> Player> that stored in
> > the static variable "LAST_SELECTED".
> >
> > It's imperative that I keep LAST_SELECTED data type as "Player".
> > I don't want give it the dynamic datatype.
> >
> > What's a more elegant way to test if LAST_SELECTED is defined 
> without> getting an Error?
> >
> >
> >
> > Normally in AS2, I would just declare it null in class variables and
> > later define it when selectPlayer is called like:
> >
> > function selectPlayer()
> > {
> > if(Player.LAST_SELECTED == null){
> > Player.LAST_SELECTED = this;
> > }
> > }
> >
> > But the testing of "null" causes an Error when a variable's 
> datatype is set.
> > So I can't use this lazy AS2 tactic anymore. ;)
> >
> > [CODE]
> >
> > import mx.core.UIComponent;
> > import mx.controls.Alert;
> >
> > class Player extends UIComponent
> > {
> > private static var LAST_SELECTED:Player
> >
> > public function Player():void
> > {
> > /*****
> > Whenever I create a new Player defining LAST_SELECTED here 
> fixes> the Error
> > But I purposely don't want each new created Player to be set as
> > LAST_SELECTED.
> > ******/
> > //I don't want this so I comment it out.
> > //--->Player.LAST_SELECTED=new Player();
> > }
> >
> > private function selectPlayer():void
> > {
> > try
> > {
> > if(Player.LAST_SELECTED != this){
> > //Restore the last selected Player to normal scale.
> > Player.LAST_SELECTED.scaleX=100;
> > Player.LAST_SELECTED.scaleY=100;
> >
> > //Assign this current Instance as the LAST_SELECTED 
> Player.> Player.LAST_SELECTED=this;
> >
> > //Set the scale to show the new selected instance .
> > scaleX=150;
> > scaleY=150;
> > }
> > }catch(e:Error){
> > Alert.show(e.message,e.name);
> > }
> > }
> >
> > }
> >
> > [/CODE]
> >
> >
> > Thanks for your time,
> > --Keith H--
> >
> >
> > --
> > Flexcoders Mailing List
> > FAQ: 
> http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
<http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt> > 
> Search Archives: http://www.mail-
> archive.com/flexcoders%40yahoogroups.com> Yahoo! Groups Links
> >
> >
> >
> >
> >
> 


 

Reply via email to