Skip to main content
Known Participant
February 7, 2010
Answered

Adobe Documentation regarding AS3 Classes

  • February 7, 2010
  • 3 replies
  • 544 views

Hello,

At this link from Adobe's own website:

http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f30.html

It discusses Constructor Methods. They give this as an example (see below):

class Example
{
    public var status:String;
    public function Example()
    {
        status = "initialized";
    }
}

var myExample:Example = new Example();
trace(myExample.status); // output: initialized

The question is can this code run as is, or am I supposed to know I am to do the following:

1. Rewrite the class and put it in a package statement and save it as Example.as

2. Create an Fla file and place in it an import statement and the code where the instance is created.

Thanks,

Jim

P.S. If the code can run as is, how do you do that by merely pasting all the code into a FLA file.

This topic has been closed for replies.
Correct answer

youve answered your own question.  you are right you need the package and need to import it every place you use it.

so the package by the way is where your class lives in relation to the fla.   if you set your fla to look at a folder and that folder is where your class lives, then your pacakge is just package {

if you set your fla to look at a folder called src,    and you have your src folder has a folder called your documentClass  then your pacakge is package.documentClass{

if you dont have the fla pointing to any folder  and you dont have a folder structure for your class you can just write package{

and import would be exatcly as it looks in your package.

import documentClass.Example()   or import Example()

3 replies

jimfid45Author
Known Participant
February 7, 2010

Thanks to Ifezec and Ned  for the answer / confirmation.

Ned Murphy
Legend
February 7, 2010

I believe your items 1 and 2 are what you are expected to know by the time you get to this section, though I haven't been thru the documentation to see what precedes this section.  You cannot write the class code into an fla and have it work, just the two lines that follow it.

Correct answer
February 7, 2010

youve answered your own question.  you are right you need the package and need to import it every place you use it.

so the package by the way is where your class lives in relation to the fla.   if you set your fla to look at a folder and that folder is where your class lives, then your pacakge is just package {

if you set your fla to look at a folder called src,    and you have your src folder has a folder called your documentClass  then your pacakge is package.documentClass{

if you dont have the fla pointing to any folder  and you dont have a folder structure for your class you can just write package{

and import would be exatcly as it looks in your package.

import documentClass.Example()   or import Example()