Question

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

Was it helpful?

Solution

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 {

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top