03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Specifies that a variable or function is available to any caller. Because variables <strong>and</strong> functions<br />

are public by default, this keyword is used primarily for stylistic reasons. For example, you<br />

might want to use it for reasons of consistency in a block of code that also contains private or<br />

static variables.<br />

Parameters<br />

name:String - The name of the variable or function that you want to specify as public.<br />

Example<br />

The following example shows how you can use public variables in a class file. Create a new<br />

class file called User.as <strong>and</strong> enter the following code:<br />

class User {<br />

public var age:Number;<br />

public var name:String;<br />

}<br />

Then create a new FLA or AS file in the same directory, <strong>and</strong> enter the following ActionScript<br />

in Frame 1 of the Timeline:<br />

import User;<br />

var jimmy:User = new User();<br />

jimmy.age = 27;<br />

jimmy.name = "jimmy";<br />

If you change one of the public variables in the User class to a private variable, an error is<br />

generated when trying to access the property.<br />

See also<br />

private statement<br />

return statement<br />

return[expression]<br />

Specifies the value returned by a function. The return statement evaluates expression<strong>and</strong><br />

returns the result as a value of the function in which it executes. The return statement causes<br />

execution to return immediately to the calling function. If the return statement is used alone,<br />

it returns undefined.<br />

You can't return multiple values. If you try to do so, only the last value is returned. In the<br />

following example, c is returned:<br />

return a, b, c ;<br />

If you need to return multiple values, you might want to use an array or object instead.<br />

194 ActionScript language elements

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!