chris
chris

Reputation: 79

How to take the actionscript from an as3 package and use it in .fla

This morning i stumbled upon this source code for a miner game : http://www.emanueleferonato.com/2010/10/22/create-a-flash-game-like-gold-miner-as3-version/

The problem is that I never used packages and classes before ( I only worked with as2 ) .

I need the code from the AS files to be in the timeline AS but cant figure out a way to have it there and working .

If anybody knows how please tell me .

I tried copy/pasting the code , removing the package,class and private text and it still doesn't work .

Any help is apreciated.

Chris

Upvotes: 1

Views: 1299

Answers (2)

PatrickS
PatrickS

Reputation: 9572

You simply need to put all this packages in their own file and name the file after the class name, for instance the Main class should be saved as Main.as.

After you've saved each class in its own .as file , take all these files and copy them in the same folder as your fla. The reason for this is that the packages don't specify a path ( something like com.example for instance ) , so they need to be at the same directory level as your fla.

Finally , just use the Main class as your Document Class, here's a tutorial , there are plenty of examples on the web anyway...
http://www.heaveninteractive.com/2008/03/04/introduction-to-the-document-class-in-actionscript-30-tutorial/

Test your swf...

Upvotes: 1

Demian Brecht
Demian Brecht

Reputation: 21378

I assume that AS3 package lookups work pretty much like AS2 classes in that they're relative to root directories pointed to by your Flash movie.

For example, the package i.am.a.test{}, would exist at:

i/am/a/test

(Of course, the path above would be relative either to the .fla using it, or to another directory specified in your movie settings.)

...And with a class definition would be something like:

package i.am.a.test
{
    class ReallyATest
    {
    }
}

So, what you need to do is ensure all classes used in the .fla exist in the path relative to the .fla you're working on. Here's a little more info you can use to read up on working with packages: creating a package

Upvotes: 0

Related Questions