Author Topic: Improvements  (Read 14807 times)

  • Administrator
  • Sr. Member
  • *****
  • Posts: 407
    • View Profile
Re: Improvements
« Reply #60 on: January 26, 2020, 10:15:13 pm »
Please avoid using identifier "undefined". Keywords undefined and null (without quotes) are reserved for nonexistent status of tested object/variable/property.
So

if (_root.species != undefined) //means "if variable _root.species even exists"
{
}
else //otherwise _root.species variable doesn't exist (typically when scene file runs standalone in a browser, not in game launcher)
{
 // do some default choice.
 // you cannot address by null/undefined as null pointer is usually unrecoverable program exception or fatal error if not caught by Flash Player.
}


The correct script selecting right frame should be:


gotoAndStop("whatever_is_default_for_all_cases"); // select the absolute default frame for all cases first
if (_root.genus != undefined) //means "if variable _root.genus even exists"
{
  gotoAndStop(_root.genus); // select frame default for particular genus. If there is no frame label matching current genus value, it will stay in the frame selected by the first gotoAndStop()
}
if (_root.species != undefined) //means "if variable _root.species even exists"
{
  gotoAndStop(_root.species); //select frame by species. If no frame label matches current species value, it stays it the frame selected by genus in previous condition.
}


And careful about uppercase letters: ActionScript is case sensitive. So gotoAndStop() is a method of MovieClip class object (DefineSprite in SWF) while GotoAndStop() is different thing not defined yet so it will do nothing when called and you will get no warning or clue why it doesn't work.