Hi,
another lazy way;
function selectPlayer()
{
if(Player && Player.LAST_SELECTED == null){
Player.LAST_SELECTED = this;
}
}
Peace, Mike
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--
--
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'.