You didn't say what error you're getting when you compare with null (?)
On 4/23/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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
> Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
> Yahoo! Groups Links
>
>
>
>
>