AS3 Avoider game tutorial document class - actionscript-3

everyone! I'm trying to find an answer to a problem that I've found with the AS3 Avoider Game Tutorial by Michael James Williams, found here.
More specifically, I'm stuck on the part where you have to set the "PlayScreen" to a differen Document Class. I right-click on the symbol in the library, select "Properties," and get a pop-up screen that sets up Class, Base Class, linkage...but nothing in there about "Document Class." It doesn't look like the screenshot.
So what do I do, here?? How do I find the document class?

It looks like you should have declared AvoiderGame.as as your document class, originally. That's the instruction in the first section of the tutorial under 'Making an Enemy.'
This instruction also tells you how to declare a document class.
Now, in section 3, you're instructed to create a new class that will become the document class instead of AvoiderGame.as. It just happens that you're asked to name this class 'DocumentClass.as' But you MAKE it your document class (which, of, course, is the point-of-entry into the game) in the same way as before: by putting it's name -- DocumentClass -- into the document class box in the Properties panel.

Related

Issue with Document Class and Tutorial

So I've been following this tutorial on AS3 and Flash. Its been going well until, note I have tried to contact the writer of the tutorial and had no reply. Here's what it tells me to do;
Right-click PlayScreen in the library, select Properties, and check Export for ActionScript. This time, instead of accepting the default value, enter the name of your document class. Click OK.
So it pops up an error, first we’ll have to make a new document class, since no two different objects can share the same class. Cancel the Properties box.
Hit File > New and select ActionScript File. Enter the (by now familiar) code.
Save this in the Classes directory as DocumentClass.as. (There’ll be no confusing the purpose of this file!) Now, back in your FLA, change the document class to DocumentClass.
Check everything’s fine by clicking that pencil icon — if it’s all OK, that should bring up the AS file that you just created.
// So this bits all fine, its the next that i'm stuck with:
Now you can set the PlayScreen‘s class to AvoiderGame. So do so!
// So I go ahead into the properties and change the name but then it pops up with the same error as before: 'Please enter a unique class name that is not associated with other library symbols'
What does this mean!? How do I resolve this!?
Full tutorial here:Flash Tutorial
Its hard to tell what you are trying to accomplish without knowing what all the parts you are referring to actually do, which are objects in the library and which are classes, but maybe this can help:
First of all, document class in AS3 typically refers to the project's main set of code that initializes the app. This class can be called anything but is often called Main, and is entered in the property panel that is displayed when you click the projects main stage in the field called class.
Now, when linking a class to an object in the library, its a little different. In the library object's property panel, tick the box for Export for Actionscript, and put a unique name in the top box. This is what you reference in your code to call it, like new somethingOrOther() or using the pic below as an exaample, new Ball(). The second box is the base class, pathed to where it lives in your code base. This is the class you will write that actually controls the object you've linked the class to. Giving a linked object a base class and a unique identifier allows you to use the same base class for multiple linked objects.
Note that when you do this approach, Flash will warn you that there is no class associated with Ball and one will be created for you. Don't worry, this is normal behavior. If you set this up properly, your object will still be controlled by its base class.

Actionscript 3: Adding a MovieClip (from library but not on stage) to a Sprite declared within a seperate class

What I am trying to do is add a MovieClip which I have created, but deleted from the actual stage itself, from a seperate class to a sprite which I declare in the document class.
The link between the main document class and the others works fine, as well as references to the stage, from the class in question.
It is only one line of the function which is giving me the error: Type was not found, or is not compile-time constant:SequenceA
I have already tried changing the settings for 'Export for Actionscript' in the library properties and still get the same message every time.
Pretty lost with this one so any help is appreciated. Cheers!
What have you set as the "Class" in your Export for ActionScript settings? It looks like you're trying to refer to an instance rather than the class itself. For example, mc is an instance of the MovieClip Class.
Assuming you've chosen the Class "SequenceA", you would do this instead:
var seqA:SequenceA = new SequenceA();
There's a little bit more detail about objects and classes here.

Working with OOP and TimeLine

I'm having a problem using flash CS6 (or CS*), where I want to be able to create symbols in the interface and link them to an as3 class. The problem is that when editing the class the code hints don't work correctly, i suppose because the CS* interface doesn't tell the code the object types.
For example:
I create a symbol and link it to a class (myclasses.SomeDisplayObject)
I now create and edit this class in the flash pro code editor, but the editor doesn't know any of the object properties.
To combat the problem I've been creating private properties on the class and assigning them in the construct. This way I can set the type and code hinting works. This is a real nuisance and I have in one class 50 lines of variable assignments.
There must be a better way of doing it and I'm hoping someone here knows about it.
Just turn off "declare stage instances automatically" and declare them as public properties. For more specifics on how to deal with OOP on the timeline, check out http://www.developria.com/2010/04/combining-the-timeline-with-oo.html and http://www.meetup.com/atlflex/files/
The IDE (or any other code tool you choose to use, like Flash Builder), should then recognize your instances.
You could use a different editor. For instance, there is FlashDevelop

When do we need to add reference to the stage from one class to another

When do we need to pass reference to the stage from one as3 class to another like in this tutorial
http://asgamer.com/2009/as3-flash-games-for-beginners-firing-weapons-with-delays
he added a ref to the stage from the bullet class to the ship class
as I understand a reference is needed when we want to use a function in a certain class from another class but why do we have to reference the stage isn't it only one stage for the whole project or each class has it's own stage ?
I am very confused
Thanks
Only objects that are connected to a stage will be shown on screen. In the tutorial he is adding the lasers onto the stage display list so that it appears on screen. Until it is added, it will not be rendered regardless of the visible property.
See this for more info about the display list.
#Geotarget is correct, but the answer is a little bit indirect.
Objects that are not on the display list do not actually have a reference to stage. So if, for example, you create a var mc:MovieClip = new MovieClip(); which is not added to the display list (as in addChild(mc)), then mc.stage will be null. (Also, checking if(mc.stage){[...]} is also a way to verify if the MovieClip is part of the display list yet.)
So you can pass a reference to the stage to non-display-list objects to allow them access to things like stageWidth.
Yes, a reference is needed when you wanna have to access a function present in that particular class ( to which reference belongs). This is one of the uses.
There is only one stage for the whole project.
In the tutorial you are following, both the classes are using the reference of a COMMON Stage, so that both of them can access the Stage.
It's like giving the address of a place to two people. So that both of them can go there. Naturally, giving addresses doesnot mean, we are building two places for each of them.
V.

Explanation of Base Class (Flash) and inheritance

I have a MovieClip called PopUp where I wrote some code.
I need to make another MovieClip that uses pretty much the same code...can I just use the PopUp class as the base class for my other MovieClip?
They look different but they have the same instances on the stage and stuff.
You can just create a new class called PopUpBase, and let your new MC's extend that class. Generally changing the base class in the IDE can cause some problems, so it's best practice not to, but to create classes (and .as files) for each MC that needs code.
Depending on what you're doing with this, it might be okay just to change the base classes to PopUpBase (in the IDE) :)