View Full Version : import external class with Flex SDK..?
dandylion13
September 17th, 2009, 02:31 PM
Hello,
I'm using Textmate to complile AS3.0 code. I need to import an external class library that isn't relative to the project or document root. It's a directory called "agd" which is in this this location of the Flex SDK installation directory:
frameworks/libs/agd
I've udated the flex-config xml file so that it looks in that location for the classes
<source-path>
<path-element>libs/agd</path-element>
</source-path>
In my class I've use the this import statement:
import agd.utils.StatusBox
When the code compiles, it seems to be able to navigate to "agd.utils" but can't find the actual class, "StatusBox"
... I'm sure there's something very basic that I'm missing out?
I'd really appreaciate some help from anyone who might be able to point me in the right direction... thanks very much :)
roarindustries
September 17th, 2009, 02:50 PM
Surely if you're importing agd.utils.StatusBox then the compiler should be looking in libs?
e.g.
<source-path>
<path-element>libs/agd</path-element>
</source-path>
// import utils.StatusBox
<source-path>
<path-element>libs</path-element>
</source-path>
// import agd.utils.StatusBox
wvxvw
September 17th, 2009, 02:52 PM
First, why would you put your library there? You really cannot find a worse place on your computer to put it... Second, the path should be relative to the compiler or absolute. Better use absolute though, and make it:
<source-path append="true">.... This is the way to tell the compiler you're wanting it to watch multiple location.
dandylion13
September 17th, 2009, 03:00 PM
Thank you very much for your quick response! Of course, that makes perfect sense!
However, I made these changes, and I'm still getting the same complier error
1. In flex-config.xml:
<source-path>
<path-element>libs</path-element>
</source-path>
2. In the AS file (remains the same):
import agd.utils.StatusBox;
3. The compile error is the following:
Thank you very much for your quick response! Of course, that makes perfect sense!
However, I made these changes, and I'm still getting the same complier error
1. In flex-config.xml:
<source-path>
<path-element>libs</path-element>
</source-path>
2. In the AS file (remains the same):
import agd.utils.StatusBox;
3. The compile error is the following:
Error: Definition agd.utils:StatusBox could not be found.
import agd.utils.StatusBox;
^
(The pointer is under the "S")
roarindustries
September 17th, 2009, 03:07 PM
Listen to wvxvw (http://www.kirupa.com/forum/member.php?u=100992)...
Is that directory even called libs? Is it lib? I don't even have the sdk installed, was just a general answer.
dandylion13
September 17th, 2009, 03:21 PM
Thanks wvxvw!
I tried a realtive path,
<path-element>../libs</path-element>
but the complier then couldn't find the libs folder at all.
I'm not exactly sure how to implement your suggestion of using an ablsoute path, would it be somthing like this?
<source-path append="true">
<path-element>/path</path-element>
</source-path>
At the moment it seems that the complier can actually find the class directories, but it chokes on the actual class name, StatusBox. I've test other classes from the same directory and compiler always fails at the class name.
I do have another question though: where do you suggest is the place to keep class libararies?
Thanks again for your help :)
dandylion13
September 17th, 2009, 03:23 PM
Is that directory even called libs?
Yes, it's "libs".. thanks for asking :)
wvxvw
September 17th, 2009, 03:37 PM
../libs is not a relative path to compiler unless you compiled SDK on your own and moved things around... the compiler is the MXMLC or MXMLC.exe file (depends on your OS) and it's in the bin folder in the root SDK folder. From what it sounds you have saved your SWC into <SDK root folder>\frameworks\libs. I have absolutely no idea as to why would you want to do such thing, this folder is definitely not for you to store some 3rd party classes... Anyways, the best way to go about such things is to make the path absolute and if you need several projects working on the same set of classes - simply create a build file per project. No point in sharing the same build file across many projects since they are going to have their own classpaths anyway...
dandylion13
September 17th, 2009, 04:15 PM
Thanks for your patience everyone!
From what it sounds you have saved your SWC into <SDK root folder>\frameworks\libs. .
Yes, that's exaclty where it is. However "agd" is just a directory, not an SWC. Does it have to be an SWC file?
Maybe I should explain in more detail what I'm trying to do:
I'm busy migrating from the Flash IDE to Textmate. In Flash I've set the classpath to a collection of classes that I use with all my projects. It points a directory that contains all my classes and packages.
I'm trying to import these same classes into code that I'm now compiling with the Flex sdk (fcsh compiler) through Textmate. So far though, I haven't found a way to help the complier find these classes.
For testing purposes I've now moved the directory to my hard drive root and have made this change to flex-config:
<source-path append="true">
<path-element>/agd</path-element>
</source-path>
The compiler can find this, but still can't open the classes. I'm sure there's something really small I'm overlooking?
wvxvw
September 17th, 2009, 04:59 PM
Oh, I'm really sorry, didn't pay enough attention... it should be actually like this:
<library-path append="true">
<path-element>C:\www\projects\xmlhelpers\lib\styles.swc</path-element>
. . .
I.e. if you're targeting SWC (not a directory with AS classes), then it's library-path, not source-path.
And really, better make the path absolute... and move that SWC to some other folder. It shouldn't harm, but, anyway, it's just like as if you wanted to call your class flash.display.MovieClip2 :) While you can do it, that would be a very confusing move for other people trying to work on your project if need be.
dandylion13
September 17th, 2009, 06:10 PM
if you're targeting SWC (not a directory with AS classes), then it's library-path, not source-path.
Is it possible to target directories or do you have to target an SWC?
wvxvw
September 17th, 2009, 06:54 PM
Both are possible, but you target directories of AS files and you can target SWC in 3 different ways:
- external (the classes in the SWC are only used for type checking but not embedded)
- on-demand (if the class is used, it will be embedded)
- complete (all the classes from SWC will be compiled into SWF).
So, this is just different from AS files because you cannot force compilation of all the AS files in the source path.
dandylion13
September 17th, 2009, 08:00 PM
Thank you wvxvw :)
I'm sure somewhere I've got something set up incorrectly.
I will do some more checking. I'll check my all class locations, flex-config settings and Textmate settings.
This is quite a new area for me so I appreciate all your help
dandylion13
September 18th, 2009, 01:03 AM
Hi Everyone,
I'd appreciate if someone could tell me whether my new setup looks Ok.
I've got a directory called "agd" in my hard drive root. It contains all the classes I want to import.
I've modified flex-config like this:
<source-path append="true">
<path-element>/Volumes/Macintosh HD/agd</path-element>
</source-path>
In my document class I'm importing the class I need from the "agd" directory like this:
import utils.TextBox;
(The path to the imported class is: agd/utils/TextBox.as)
Does this look right?
It seems to be from what I've been able to research, but the compiler still cannot find TextBox (or any other classes in the "agd" directory).
If everything looks OK... is the problem perhaps something else?
dandylion13
September 18th, 2009, 10:14 PM
Problem solved!
I think it was a glitchy SDK installation. I noticed that fsch and the other files in the bin folder were not being recognized as unix executables - OSX thought they were text files.
I did some research and apparantly files can lose their signature if they're zipped by an OS that is different from the one that's unzipping it. There's no way to repair that, except by manually editing each file, which I wouldn't have the first clue to go about doing.
I ended up downloading the Flex 4 SDK beta, and noticed the files in that installation seemed to have been zipped properly - they were resolving as unix executables. I pointed my Textmate installation to the new installation, and everything works.
Thanks again for all your help everyone, and wvxvw, you have a couch to surf to if you're ever in Canada!
PS: If anyone else has trouble getting the sdk set up with Textmate, let me know.. a lot of the material that turns up first in search engines is out-of-date and not entirely comprehensive
wvxvw
September 19th, 2009, 06:16 AM
Thanks, btw, I'm working right next door to the Canadian embassy, so... who knows :)
And, happy to hear it was solved.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.