Log in

View Full Version : It's time to start using external code



evan
11-06-2008, 07:01 PM
:mad:OK I have gone to school and learned about :

Inheritance, Encapsulation & Polymorphism

but to put it into practice I NEED to know some BASICS in how to structur, name and link .as files to .fla files correctly.

The tutorials I find talk about oop and I practice exples and my code does nothing.



so I started from scratch with the most barebones example:

1)create test.fla
2)create test.as
3) make sure test .as targets test.fla in the top right corner
4) in test.as I plug in these lines:




package
{

public class test
{
public function test():void
{trace ("hello");
}

test();

}

}




5) I save everthything and run test.fla or publish test.swf and nothing happens.

Medyman
11-08-2008, 03:13 PM
I'm not exactly sure what you're doing. Are you setting this as the Document class? Or are you attaching it to an object?

BLiZZaRD
11-08-2008, 08:00 PM
You have to call the .as files from the .fla.. in frame 1 actions layer put this:



#include "test.as"


save, publish, upload.

Medyman
11-09-2008, 02:19 AM
You have to call the .as files from the .fla.. in frame 1 actions layer put this:



#include "test.as"


save, publish, upload.

Blizz, that would be true for AS2. I'm pretty sure Evan is using AS3 and CS3's OOP techniques.

evan
11-10-2008, 11:40 AM
I think this would be a document class as in this would not be in a folder but reside in the same folder as the fla.

How is it different? I know partly because I have worked with other scripts but not on my own from scratch. if it's in a folder I think ithe file/class and folder need to be named the same.

In this case I name the .as the same as the .fla and ensure they are linked via the upper right hand corner selector.

Medyman
11-10-2008, 02:08 PM
I'm not sure what you're referring to in terms of the "upper right hand corner selector". You could have workspace configured than I have mine, but I don't see anything related to relating AS classes in the upper right hand corner of my screen.

The Document class is set in the Properties panel.

If you haven't already, watch the following tutorials by Lee Brimelow. I think they'll give you a better idea of using OOP techniques with AS.

Introduction to OOP (http://gotoandlearn.com/play?id=48) (AS2)
Using the Document Class (http://gotoandlearn.com/play?id=43)
Object Oriented Scrollbar 1 (http://gotoandlearn.com/play?id=71)
Object Oriented Scrollbar 2 (http://gotoandlearn.com/play?id=72)

Are you using CS4 now?

evan
11-10-2008, 05:07 PM
I did catch something I missed from the document class tutorial in the properties I forgot to set up the script in the Document class window. It figures it would be something dumb like that.

How do I create more than one script and appy it to an fla?

BLiZZaRD
11-11-2008, 02:32 PM
Blizz, that would be true for AS2. I'm pretty sure Evan is using AS3 and CS3's OOP techniques.

So attaching an external .as file is different in AS3? Or am I missing the actual question?

Medyman
11-11-2008, 04:57 PM
So attaching an external .as file is different in AS3? Or am I missing the actual question?

Yup, it's different and it really depends on what you want to do. You can "include" external ActionScript using the include directive.

AS3 gets rid of the the # in front though. So, to include regular AS3, you might do something like:


include "myactionscript.as"

However, these included bits should really not be classes. If you're creating a Document class, you can attach it via the properties panel. Or, if you're attaching classes to objects, you can set it in the object's linkage properties.

BLiZZaRD
11-11-2008, 04:59 PM
hmmm... interesting. In 3 versions of Flash we went from not using .as at all to relying on them completely.. funny.

Medyman
11-11-2008, 05:00 PM
I did catch something I missed from the document class tutorial in the properties I forgot to set up the script in the Document class window. It figures it would be something dumb like that.

How do I create more than one script and appy it to an fla?

Are you still working on your drawing application? If so, the schematic would look something like this:

A class for the pencil tool is attached to your pencil movieclip/object.
A class for the eraser tool is attached to your eraser movieclip/object.

It's called object oriented programming for a reason.

If you need to call multiple classes within your Document class, use the import directive.

Medyman
11-11-2008, 05:04 PM
hmmm... interesting. In 3 versions of Flash we went from not using .as at all to relying on them completely.. funny.

Doesn't it have to? Adobe is adding a lot more power to the timeline -- CS4 is an example. But, as Flash gets more powerful as a platform, it has to increase the flexibility, extensibility and capability of ActionScript.

I don't think that it's a matter of relying on AS completely, but that's where more of the innovation is going to be in the future.

BLiZZaRD
11-11-2008, 05:12 PM
don't misunderstand me... :P I meant relying on the external .as files, not AS itself.

Other than organizational abilities I see nothing wrong with putting script on the MC or timeline as needed. But Adobe is making it so we MUST use external files for the projects.

Not saying it's a bad thing, just something I have noticed.

Medyman
11-11-2008, 05:18 PM
don't misunderstand me... :P I meant relying on the external .as files, not AS itself.

Other than organizational abilities I see nothing wrong with putting script on the MC or timeline as needed. But Adobe is making it so we MUST use external files for the projects.

Not saying it's a bad thing, just something I have noticed.

Oh...I see what you mean. Sorry about the confusion.

To your point though, it's not so much Adobe that's making it so we MUST use external files. You can still do everything within Flash.

The desire for using external AS files is two-fold:
1) More organization through OOP
2) Better coding environment. The Flash IDE has been horribly neglected. If nothing else, they should just merge in the Flex 3 IDE into Flash.

evan
11-11-2008, 05:59 PM
actually you don't even have to rely on them completely. As I have been learning to code I have been doing all timeline based code -but as my project grew I realized down the road I will evidently need to take this step.

3000 lines and counting...........

I use alot of comments and keep it clean but it will have advantages once I figure this out.

Hard core coders do this almost exclusively.

evan
11-11-2008, 06:18 PM
A class for the pencil tool is attached to your pencil movieclip/object.
A class for the eraser tool is attached to your eraser movieclip/object.

It's called object oriented programming for a reason.


tha's where this is going

unless I use several different .as files and place them in a folder

keeping the files seperate also allows work to be shared and edited instead of having poeple take turns on the same .as file or swf


as it is now I have it all in one .fla in one script -a pain to edit -great for learning how to code but the project needs to be planned better now.