Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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:mac_doggie@hotmail.com
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:mac_doggie@hotmail.com
    : the Netherlands...
    :

    ;-)
    -mac-
    mailto:mac_doggie@hotmail.com
    the Netherlands...
Sign In or Register to comment.