Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple classes in ActionScript package?

I have read that you can only have one class by package in ActionScript. If you need helper classes, you have write this classes out of the package. Example:

package {
  public class A {}
}


class B {}

However, I found the following example in the adobe web site(: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f9e.html):

package flash.xml 
{ 
  class XMLDocument {} 
  class XMLNode {} 
  class XMLSocket {} 
}

In the following Web page (http://www.adobe.com/devnet/actionscript/learning/as3-fundamentals/packages.html), they said that you can only write one class of a package by a file:

// SampleCode.as file 
package samples{ 
  public class SampleCode {} 
} 

// CodeFormatter.as file 
package samples { 
   class CodeFormatter {}
}

Then my conclusion: you cannot write multiple classes of a package by file, right?. And this restriction is just to promote the good practices in AS3, right?

Sorry, if this question is too simple.

like image 593
Naive Developer Avatar asked Mar 13 '13 15:03

Naive Developer


People also ask

What is a class in ActionScript?

Classes are external ActionScript files that define objects; they are stored and organized in a specific directory structure in the Flash CS3 program directory (Figure 4.1). To use them in your code, you have to import them.

When creating a new ActionScript 3.0 class the declared package name should match which aspect of the class file?

The name of the class declared inside the package definition must match the name of the source file. ActionScript 3.0 also provides more flexibility in the way you declare packages.


1 Answers

Of course you can have multiple classes in the same package

file mypackage/MyClass1.as:

package mypackage {
    public class MyClass1{

    }
}

file mypackage/MyClass2.as:

package mypackage {
    public class MyClass2{

    }
}

But you can't have more than one public class per file (which should have the same name as the class).

You can have the helper classes outside the package block (in the same file), they are accessible only by other classes within that file:

file mypackage/MyClass3.as:

package mypackage {
    public class MyClass3{

    }
}

class HelperForClass3Only() {}
like image 62
Majid Laissi Avatar answered Oct 23 '22 10:10

Majid Laissi