开发者

how to import a class from a parent directory in actionScript 3

I have seen similar questions, but not this specific problem

I have a folder structure like this:

root

+ com
    - classes
          - class1.as
          - class2.as
    - other
          - otherClass.as
+ folder1
    - file.swf
- index.swf

I want to import a class from com/classes/

From index.swf I would do:

import com.classes.class1;

import com.other.otherClass;

And I have no problem importing, but when I do the same on file.swf (which is in a subfolder), the class can't be found.

So, how can I imp开发者_运维问答ort in file.swf class1.as if the route is: ../com/classes/class1.as


If you were using FLash pro, go to File then Publish Settings.

Click on the Flash section Click on the Settings button beside ActionScript version.

Then add your class path there.


assuming com and folder1 are in the root directory, it's still import com.classes.class1.

Depending on the IDE you're using, you can have this done for you automatically. In FlashDevelop, click on the class string (e.g. new class1();) and press ctrl+shift+1, and it'll add the import for you. In FlashBuilder, it's ctrl+space I think.

If you're using the Flash IDE itself, I'm not sure if there is a command. The Flash IDE is pretty poor when it comes to coding ;) Consider another dev environment - it'll save you a ton of time in the long run. Try FlashDevelop (free): http://www.flashdevelop.org/wikidocs/index.php?title=Main_Page


There's no possibility to import the classes included in SWF file this way. You need to it with Loader class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜