all groups > flash actionscript > april 2006 >
You're in the

flash actionscript

group:

Understanding variables


Re: Understanding variables David Stiller
4/30/2006 6:15:41 PM
flash actionscript:
Park2,

[quoted text, click to view]

Scope is a bit different in Flash. ActionScript features a special
_global object available to all timelines; that is, all movie clips,
including the main timeline (the main timeline is indeed a movie clip -- not
immediately obvious, but helpful to know). You may assign properties to the
_global object that are available everywhere.

e.g.
_global.myNum = 5;
_global.myStr = "Hello world";

Variables defined in a timeline are global to that timeline.

e.g.
// script in a frame of the main timeline
var myNum:Number = 5;

Note the ability to add strong typing to variables declared in this way
(above). Here, below, is another way to declare a varible in a timeline;
this time, by referencing a movie clip by its instance name. This is
functionally the same as entering the clip's timeline and using var there.

e.g.
myClip.myNum = 5;

Variables declared with the var statement inside functions are local to
that function (i.e., not available to any timeline).

e.g.
function myFunc() {
// scoped to this function only
var myNum:Number = 5;
}

[quoted text, click to view]

_root always points to the main timeline of the currently active
document. The default document is _level0, so unless you purposefully load
or create content in _level1, _level2, etc., _root points to _level0. If
your published SWF is loaded into another SWF, then any mention of _root
(even in the SWF loaded by the parent) refers the the *parent* SWF's main
timeline. In other words, there is only one _root, and it's always the
bottommost (or topmost, whichever you prefer) timeline.

[quoted text, click to view]

See above. And see this article ...

http://www.quip.net/blog/2006/flash/actionscript-20/is-root-evil

[quoted text, click to view]

The global property "this" always refers to the timeline or object to
which it is scoped.

[quoted text, click to view]

Heh, I'll need more detail in order to answer that one. ;)

[quoted text, click to view]

The Actions panel gives you access to all scripts in a vertical
treeview. One of the banes of FLA files, especially older ones, is the
likelihood that ActionScript will be scattered helterskelter. Current best
practices recommend that code be placed in a layer dedicated just for
scripts, and, in fact, in as few frames as possible.


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."

Re: Understanding variables David Stiller
4/30/2006 6:17:11 PM
[quoted text, click to view]

I should have also mentioned class files. Since Flash MX 2004, it has
been possible to write classes as external text files (generally .as
extension). In such classes, variables can be established as public or
private.

See Joey Lott's three-part ActionScript 2.0 Primer ...

http://www.person13.com/articles/


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."

Understanding variables Park2
4/30/2006 10:50:42 PM
I am from a delphi background. In delphi I either declare a variable as
public (the variable is available throughout the project) or private (the
variable is used within a function).

In flash what is the relationship throughout the project?

_root
_level10
this.

etc etc......

Also how do I show all the code from a project within one window.


Any help or tutorials etc appreciated


Re: Understanding variables Jeckyl
5/1/2006 12:00:00 AM
There are a number of objects visible from anywhere in the movie.

_global .. which is an object used to hold other variables you wish to have
global access to. When accessing (not setting) a variable in _global, you
can omit the "_global." prefix

_levelN (where N is a level number) .. is a global name for the root
timeline of the corresponding level. Levels are complete flash movies that
playing one infront of another, with high level flash movies playing
above/infront of lower level flash movies., with the main flash movie (level
0) at the back/behind all other levels.

Within a given level there is a _root variable available throughout the
level which is a reference to the main (root) timeline object

Within a movieclip there is a special variable preset called _parent that
refers to the parent movieclip/scene timeline.

If you are running a method or a frame action, then the 'this' variable
refers to the object/movieclip context the method belongs to
--
Jeckyl

Re: Understanding variables Laurent
5/1/2006 12:00:00 AM
_level10, isn't it level0 ?

"Park2" <stevew@parkforce.com> a écrit dans le message de news:
e33bf5$deu$1@forums.macromedia.com...
[quoted text, click to view]

Re: Understanding variables SteveW
5/9/2006 6:17:55 PM
Thanks guys


[quoted text, click to view]

AddThis Social Bookmark Button