classes - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

classes

mac_doggiemac_doggie Posts: 488Member
Hi,

I'm a php/Javascript programmer and recently started with flash (CS3) (Action Script 3).

I'm a bit confused on how classes work in Action Script. I creatred a new project, and put the following code in the first frame:

[code]
include "myfile.as"
stop();
[/code]

myfile.as
[code]
class MyClass {
public function MyClass() {
trace('MyClass::Constructor');
}

}

var obj:MyClass = new MyClass();

[/code]

and I get:
[code]
1131: Classes must not be nested.
[/code]

Can anyone tell my wat's wrong here?
;-)
-mac-
mailto:[email protected]
the Netherlands...

Comments

  • mac_doggiemac_doggie Posts: 488Member
    I already found out how it works thanks... for those who are having the same kind of troubles:

    If you select the Stage, you see a filed in the properties section of the screen something like document class or so. If you fill in Main, and then make a file Main.as with:
    [code]
    package {

    class Main {
    function Main() {
    trace("Main application");
    }


    }
    }
    [/code]

    then it should work. You can then make as many classes as you wish, but each put them in a file with exactly the same filename as classname, and put package around it. You can also put multiple classes in one package I think but I think it's better to put them each in their own file.


    : Hi,
    :
    : I'm a php/Javascript programmer and recently started with flash
    : (CS3) (Action Script 3).
    :
    : I'm a bit confused on how classes work in Action Script. I creatred
    : a new project, and put the following code in the first frame:
    :
    : [code]:
    : include "myfile.as"
    : stop();
    : [/code]:
    :
    : myfile.as
    : [code]:
    : class MyClass {
    : public function MyClass() {
    : trace('MyClass::Constructor');
    : }
    :
    : }
    :
    : var obj:MyClass = new MyClass();
    :
    : [/code]:
    :
    : and I get:
    : [code]:
    : 1131: Classes must not be nested.
    : [/code]:
    :
    : Can anyone tell my wat's wrong here?
    : ;-)
    : -mac-
    : mailto:[email protected]
    : the Netherlands...
    :

    ;-)
    -mac-
    mailto:[email protected]
    the Netherlands...
Sign In or Register to comment.