0

I am very new in AS3. I use FlashDevelop 4. I have no Adobe Flash, just FD (pure AS3) I have problems with classpath. I searched the database but I found nothing that could help me. So the problem is as follow.

I have the project "Testing" in C:\AS App\Testing with the file Main.as. I have, also, the folder C:\AS App\W_T. In this folder is the file write_text.as. The file Main.as looks like that:

package
{
import flash.display.*;
import flash.text.TextField;
import flash.events.*;
import W_T.write_text;
public class Main extends Sprite
{
    var t:TextField=new TextField();

    public function Main():void
    {
            stage.addChild(t);
            stage.addEventListener(MouseEvent.CLICK, write);
    }

    public function write(me:MouseEvent):void
    {
        var wt:W_T.write_text = new W_T.write_text();
            t.x = 100;
            t.y = 100;          
            t.text = wt.output();
    }
}
}

The file write_text.as looks like that:

package W_T
{
import flash.display.*;
import flash.text.TextField;
import flash.events.*;
import W_T.*;

public class write_text
{
    public function write_text()
    {
    }

    public function output():String 
    {
        var txt:String;

        txt = "From function !";
        return(txt);
    }
}
}

I make the appropriate specification in the global classpath. But I get the following errors:

Error: Type was not found or was not a compile-time constant: write_text. var wt:W_T.write_text = new W_T.write_text();

Error: Call to a possibly undefined method write_text. var wt:W_T.write_text = new W_T.write_text();

Definition W_T:write_text could not be found. import W_T.write_text;

Could you help me please to find where I have done wrong ?

Thank you.

EB

E B
  • 59
  • 1
  • 8

2 Answers2

1

The problem is the compiler isn't finding your write_text.as file. By default, it will be looking here:

C:\AS App\Testing\W_T\write_text.as

Try adjusting accordingly and see if it works. When you declare package W_T { } flash will look in a subfolder called W_T for a file with the same name as the public class.

When you declare just simply package { } with no name, it will look in the root of your class library path, which seems to be a folder called Testing if that's where your main.as file is living.

If you wanted to use a common folder for your class files (that isn't nested in an individual projects folder), you can tell flash develop where to find them by going to: project -> properties, then the Classpaths tab. By default flash develop will only look in folders relative to the project.

BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40
  • I was not clear: 'package W_T' is not in the folder C:\AS App\Testing, but in the folder C:\AS App\. So, the file write_text.as is in the folder C:\AS App\W_T. Thank you. – E B Aug 21 '12 at 20:46
  • I know, I'm saying that it's not working because it's expecting it to be in C:\AS App\Testing\W_T – BadFeelingAboutThis Aug 21 '12 at 20:51
  • Hi. Thanx, now is working and is Ok. I am wondering why it didn't work when I specified the paths as I did (i mean specifying the path in Project properties or global settings). Thabx again. – E B Aug 22 '12 at 07:34
  • You would have to add the folder AS APP for it to work if it were located at C:\AS App\W_T\write_text.as. However since your project is a sub folder of AS APP that could have strange results. Whatever path you specify, it's going to look in a sub folder called W_T since that's how you've declared your package. SO if you added the path C:\AS App\W_T\ as a class path in your project properties (which is what I suspect you were trying), it would look for your file at C:\AS App\W_T\W_T\write_text.as. – BadFeelingAboutThis Aug 22 '12 at 16:18
  • If this answer best helped you solve your problem, please mark it as correct. Also upvote any other useful answers from people – BadFeelingAboutThis Aug 22 '12 at 16:20
0

The problem is that you haven't told the compiler (flex?) where to find the file. When you add it as classpath you only tell flash develop where to find the file, not the compiler.

First of all you have to check how you compile and secondly how you can change and add classpaths for your solution.u

I usually do this through ant script and a build.xml file and I can't unfortunately remember how the "pure as3"-projects are working in regards to compiling

Daniel MesSer
  • 1,191
  • 1
  • 7
  • 13