Skip to main content
Participating Frequently
June 23, 2013
Question

including AS3 external class file

  • June 23, 2013
  • 3 replies
  • 1405 views

How do I include 2 or more external action script files in my FLA document.The first one is easy and taken care by setting the class property of the FLA document to the class file name. But if I have several external class files? I have tried the 'include' directive but the compiler complains - any suggestions?

Thanks

Joseph Karov

This topic has been closed for replies.

3 replies

User Unknow
Legend
June 23, 2013

compilier "include" only that classes that was used somewhere in the code. So as MVP's said above - you need import second class in first.

Amy Blankenship
Legend
June 23, 2013

Have one of the Classes you want to use extend the other.

jkarovAuthor
Participating Frequently
June 24, 2013

Thanks! How do I do that? Can I bundle 2 or more 'classes' in one package? I even thought to past the second class code on a frame . Surely there must be a correct way to include 2 or more class files in FLA document?

Amy Blankenship
Legend
June 24, 2013

To import the other Class, just start typing its name in an expression, and hold down the control key while hitting the space bar. Both the Flash IDE and Flash Builder will bring up a code completion dropdown. When you select the Class, the import statement will be generated.

For example, if you are in Foo and you type:

protected var bar:Bar;

Then when you have typed in the "Ba" part of the word Bar after the colon, if you use the Ctrl-Space keyboard shortcut, it should show you your Bar Class, possibly among other Classes starting with "Ba." Select "Bar" with either your mouse or your cursor, and Flash will finish the word for you and generate the import statement. Note that you can now create and use instances of Bar, but Bar won't be "merged" into Foo, which it sounds like is what you want. To do that, you'll need to do what I suggested, which is to have one Class extend another Class.

To have one Class extend the other, change the line that says "public class Foo" to "public class Foo extends Bar". Note that the two Classes must have compatible functionality and have the same base Class. I'm assuming they do, or else trying to "include" the code wouldn't work either.

Another possible solution, depending on exactly what you're trying to acheive, is to apply the second Class to a symbol in the library and use that by placing it on the stage or accessing it through code. However, you haven't given us very much to go on, so it's really difficult to help you.

Ned Murphy
Legend
June 23, 2013

If they are class files then you need to use the import directive.

jkarovAuthor
Participating Frequently
June 24, 2013

Thanks!