Michael,

> I think I mostly understood that.  But, I don't understand: 
> you *don't* have to declare your script's properties at the
> beginning of a js script? 

Here is an example behavior:

function beginSprite () {
  this.pMember = sprite(this.spriteNum).member;
  this.pText = this.pMember.text;
}

function mouseEnter () {
  this.pMember.text = "hello";
}

function mouseLeave () {
  this.pMember.text = this.pText;
}


Notice that I never declared the properties pMember and pText in the
script, yet they are in fact properties of "this" and available within
the behavior using this.<propName> access. In addition, external to that
sprite I could then access those same properties using
spriteRef.<propName> as well. So in essence, no, you do _not_ need to
specifically declare your properties in JS syntax behavior as they can
be dynamically allocated at run-time, no declaration needed. Now, let's
switch that up and declare the variables but then _not_ use
this.<propName> for access:

var pMember;
var pText;

function beginSprite () {
  pMember = sprite(this.spriteNum).member;
  pText = pMember.text;
}

function mouseEnter () {
  pMember.text = "hello";
}

function mouseLeave () {
  pMember.text = pText;
}

In the above we're declaring the two variables pMember and pText using
the var operator, in doing this we're creating variables scoped to the
script itself but not available outside the script (say hi to something
akin to a private variable!). Therefore within that script itself (the
behavior) I can simply reference the property by name, no
this.<propName> needed. But, in this second case I cannot access those
properties using spriteRef.<propName> as that will throw a script error
(property not found). 

Note, when you declare a variable using var at the top of your behavior
you then give yourself the option on how to access that property, either
by straight <propName> usage or this.<propName>. But if you do start
using this.<propName> you might then cause a dynamic property allocation
and then inadvertantly (maybe you meant to) expose that property
"publicly" via spriteRef.<propName> syntax.


Am I making sense here? If not then keep it coming and I'll do my best
to answer further questions.


Cheers,
Tom Higgins | Product Manager | Director & the Shockwave Player
Adobe Systems Incorporated

http://weblogs.macromedia.com/thiggins/

... 

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[email protected]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to