0

I am trying to just include a .as file in my flash application. I'm sure it's not that difficult and I'm just getting something slightly wrong, but at the top of my code I always put:

include {"Le Bot src/Skill.as";}

OR

import {"Le Bot src/Skill.as";}

to try and include a separate .as file. But, when I use include it comes up with the error: expecting stringliteral before left brace and when I use 'import' it comes up with the errors:

expecting identifier before left brace 
expecting semicolon before left brace

I am just a beginner to AS3, is there any way to fix this problem? Btw, if I remove the two braces on either side, then it comes up with another error

stijn
  • 34,664
  • 13
  • 111
  • 163
James Gain
  • 5
  • 1
  • 4

3 Answers3

3
import locationOfASFile.Skill;

e.g. if your Skill.as file was located inside a directory named 'LeBotsrc' which was inside a directory named 'com'

import com.LeBotsrc.Skill;

Also your as package needs to reflect it's location. So inside Skill.as you would have

package com.LeBotsrc {
crooksy88
  • 3,849
  • 1
  • 24
  • 30
  • Thanks for your response it was extremely helpful! :) It seems to work fine now, I just need to use this in a few other places and my project will be finished :D – James Gain Apr 17 '13 at 08:36
  • 1
    No problem. Remember to choose an answer as a correct one if you think it resolved your question (or whichever was most helpful). Marking answers as correct is an important aspect of stack overflow and will help increase your reputation. – crooksy88 Apr 17 '13 at 08:53
  • Done :) Thanks for your help once again – James Gain Apr 17 '13 at 08:56
1

The include directive is not much used in AS3, since organizing code using packages and classes is easy. However, inlcude has a weird thing. No ending semicolon. Try this:

include "Le Bot src/Skill.as"

So to sum it up: include is not the same as import. include does not use curly braces. include MUST NOT have a semicolon at the end of the line. inlcude must be on one line in the format of:

include "pathto/myfile.as"

Using include will add the actionscript in the specified file to the timeline where the include is used. You could also accomplish the same thing by setting a document class that extends the main timeline or a symbol in the library. Doing so adds the complexity of needing to work with classes, but classes pack more than enough power and flexibility to make up for their additional complexity.

For example, using an include, you cannot specify a function or variable to be public or private. They are all public. Using classes makes it easier to make your code Object Oriented, which is a great way to make your projects more programmer friendly.

Plastic Sturgeon
  • 12,527
  • 4
  • 33
  • 47
  • I didn't manage to get this method to work, but your information about 'include' was useful for my learning, so thanks a lot :) – James Gain Apr 17 '13 at 08:37
  • In my opinion, you're better off learning to use classes and "import" instead. Its the bedrock of almost all Actionscript 3 development. – Plastic Sturgeon Apr 17 '13 at 17:38
0

That Le Bot src\Skills.as should first be accessible by a correct relative path (package\name\class.as) from your project folder, then you do import package.name.class, placing your values instead of placeholders here. Say, you look into that Skill.as and find out:

package foo.bar {
    import baz.*
    ...
    public class Skill {

This means the AS file should be located at foo\bar\Skill.as where foo folder should be in the folder where is your FLA. In case of FlashDevelop, it should be inside src foder from *.as3proj file. Place it there, and add:

import foo.bar.Skill;

to whatever file or timeline you want to refer this class from.

Vesper
  • 18,599
  • 6
  • 39
  • 61