import question

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

import question

Colin Lieberman
Hi list. Apologies in advance if this isn't the right forum for  
general haXe language help questions.

I've read the online docs and searched the forums, and haven't found  
an explanation for the behavior I'm experiencing.

For use with the Flash 9 API, I'm creating a library swf of image  
files with swfmill.

If I use the classes for those resources directly in my main file,  
like this:

import flash.display.Bitmap;

class Blue_arrow_png extends Bitmap { public function new()  
{ super(); } }

class MyClass
{
     public function main()
     {
         var bmp_blue_arrow = new Blue_arrow_png();
     }
}

then everything works fine and I can draw the with the bitmap.

However, if I try to put the class definition in a file, like this:

package lib.resources;

import flash.display.Bitmap;

class Blue_arrow_png extends Bitmap { public function new()  
{ super(); } }

and I have my main file include:

include lib.resources.Blue_arrow_png

then the project compiles fine, but the instance of Blue_arrow_png has  
a null bitmapData property, suggesting to me that the imported class  
file doesn't have access to the resources in my library swf.

Furthermore, is there a way to include a number of class definitions  
in a single file, and include (or link in via compile.hxml) that file?

I have a script that parses a directory tree to create my xml input to  
swfmill, and it would be great if at the same time it could generate a  
nice big list of class definitions that I could import into my  
project, but I haven't found a way to make that work correctly short  
of just pasting all the definitions directly into my main file.

Thanks

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: import question

Nicolas Cannasse
> However, if I try to put the class definition in a file, like this:
>
> package lib.resources;
[...]
> then the project compiles fine, but the instance of Blue_arrow_png has a
> null bitmapData property, suggesting to me that the imported class file
> doesn't have access to the resources in my library swf.

This is because your linkage name must match the complete class name
(lib.resource.Blue_arrow_png in your case).

> Furthermore, is there a way to include a number of class definitions in
> a single file, and include (or link in via compile.hxml) that file?

Yes, you can simply add it to compilation parameters, and from your code
"import" it to be able to use all the classes it contains.

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: import question

Colin Lieberman
Thanks Nicolas, but I'm not sure I totally follow you.

I assume the compiler param you're referring to is -cp right? I can  
add -cp ./ to compile.hxml and link all the files in the current  
directory? (and if so, is this recursive?)

But as for importing in another file, import {filename} doesn't work,  
and neither does import {filename}.{classname}, so I'm not sure what  
you mean by "and from your code "import" it to be able to use all the  
classes it contains."

Thanks

On Apr 28, 2009, at 7:18 AM, Nicolas Cannasse wrote:

>> However, if I try to put the class definition in a file, like this:
>> package lib.resources;
> [...]
>> then the project compiles fine, but the instance of Blue_arrow_png  
>> has a null bitmapData property, suggesting to me that the imported  
>> class file doesn't have access to the resources in my library swf.
>
> This is because your linkage name must match the complete class name  
> (lib.resource.Blue_arrow_png in your case).
>
>> Furthermore, is there a way to include a number of class  
>> definitions in a single file, and include (or link in via  
>> compile.hxml) that file?
>
> Yes, you can simply add it to compilation parameters, and from your  
> code "import" it to be able to use all the classes it contains.
>
> Nicolas
>
> --
> haXe - an open source web programming language
> http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: import question

Nicolas Cannasse
Colin Lieberman a écrit :
> Thanks Nicolas, but I'm not sure I totally follow you.
>
> I assume the compiler param you're referring to is -cp right? I can add
> -cp ./ to compile.hxml and link all the files in the current directory?
> (and if so, is this recursive?)

-cp is just to add a search path.
You can simply add the file :

haxe -main MyApp MyClasses.hx

> But as for importing in another file, import {filename} doesn't work,
> and neither does import {filename}.{classname}, so I'm not sure what you
> mean by "and from your code "import" it to be able to use all the
> classes it contains."

Simply use :

import MyClasses;

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: import question

Colin Lieberman
Thanks Nicholas. This was very helpful.

I've written a short tutorial for my blog to try to clarify this and  
some other questions that I've spent a lot time with while learning  
haXe.

I'd certainly appreciate any feedback you or others have:

http://www.cactusflower.org/learning-flash-with-haxe

Thanks

On Apr 29, 2009, at 1:51 AM, Nicolas Cannasse wrote:

> Colin Lieberman a écrit :
>> Thanks Nicolas, but I'm not sure I totally follow you.
>> I assume the compiler param you're referring to is -cp right? I can  
>> add -cp ./ to compile.hxml and link all the files in the current  
>> directory? (and if so, is this recursive?)
>
> -cp is just to add a search path.
> You can simply add the file :
>
> haxe -main MyApp MyClasses.hx
>
>> But as for importing in another file, import {filename} doesn't  
>> work, and neither does import {filename}.{classname}, so I'm not  
>> sure what you mean by "and from your code "import" it to be able to  
>> use all the classes it contains."
>
> Simply use :
>
> import MyClasses;
>
> Nicolas
>
> --
> haXe - an open source web programming language
> http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: import question

Tony Polinelli
you need to fix the bit that says,

 "use the “flash9” tree, not the “flash” tree, unless you are making a swf that uses ActionScript 2 (instead of 3), which will not be compatible with any Flash player greater than version 8."

if you target as2 then ALL flash players (above fp6) will support it. they definately play as2 swfs



Tony Polinelli
http://www.touchmypixel.com


On Mon, May 4, 2009 at 12:56 AM, Colin Lieberman <[hidden email]> wrote:
Thanks Nicholas. This was very helpful.

I've written a short tutorial for my blog to try to clarify this and some other questions that I've spent a lot time with while learning haXe.

I'd certainly appreciate any feedback you or others have:

http://www.cactusflower.org/learning-flash-with-haxe

Thanks


On Apr 29, 2009, at 1:51 AM, Nicolas Cannasse wrote:

Colin Lieberman a écrit :
Thanks Nicolas, but I'm not sure I totally follow you.
I assume the compiler param you're referring to is -cp right? I can add -cp ./ to compile.hxml and link all the files in the current directory? (and if so, is this recursive?)

-cp is just to add a search path.
You can simply add the file :

haxe -main MyApp MyClasses.hx

But as for importing in another file, import {filename} doesn't work, and neither does import {filename}.{classname}, so I'm not sure what you mean by "and from your code "import" it to be able to use all the classes it contains."

Simply use :

import MyClasses;

Nicolas

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: import question

Colin Lieberman
Thanks, Tony, I've made the correction.

On May 3, 2009, at 8:42 AM, Tony Polinelli wrote:

you need to fix the bit that says,

 "use the “flash9” tree, not the “flash” tree, unless you are making a swf that uses ActionScript 2 (instead of 3), which will not be compatible with any Flash player greater than version 8."

if you target as2 then ALL flash players (above fp6) will support it. they definately play as2 swfs



Tony Polinelli
http://www.touchmypixel.com


On Mon, May 4, 2009 at 12:56 AM, Colin Lieberman <[hidden email]> wrote:
Thanks Nicholas. This was very helpful.

I've written a short tutorial for my blog to try to clarify this and some other questions that I've spent a lot time with while learning haXe.

I'd certainly appreciate any feedback you or others have:

http://www.cactusflower.org/learning-flash-with-haxe

Thanks


On Apr 29, 2009, at 1:51 AM, Nicolas Cannasse wrote:

Colin Lieberman a écrit :
Thanks Nicolas, but I'm not sure I totally follow you.
I assume the compiler param you're referring to is -cp right? I can add -cp ./ to compile.hxml and link all the files in the current directory? (and if so, is this recursive?)

-cp is just to add a search path.
You can simply add the file :

haxe -main MyApp MyClasses.hx

But as for importing in another file, import {filename} doesn't work, and neither does import {filename}.{classname}, so I'm not sure what you mean by "and from your code "import" it to be able to use all the classes it contains."

Simply use :

import MyClasses;

Nicolas

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: import question

Ian Martins
In reply to this post by Colin Lieberman
Colin Lieberman wrote:

> Thanks Nicholas. This was very helpful.
>
> I've written a short tutorial for my blog to try to clarify this and
> some other questions that I've spent a lot time with while learning haXe.
>
> I'd certainly appreciate any feedback you or others have:
>
> http://www.cactusflower.org/learning-flash-with-haxe
>
> Thanks
more people might find it if you linked to it from the haxe wiki.
http://haxe.org/doc/flash

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: import question

Colin Lieberman
Good suggestion. It looks like that page is focussed mainly on  
resources available at haXe.org (plus links to the Adobe docs), so I  
added a section "Offsite tutorials".

If that's inappropriate I'd be happy to remove it.

On May 3, 2009, at 4:33 PM, Ian Martins wrote:

> Colin Lieberman wrote:
>> Thanks Nicholas. This was very helpful.
>>
>> I've written a short tutorial for my blog to try to clarify this  
>> and some other questions that I've spent a lot time with while  
>> learning haXe.
>>
>> I'd certainly appreciate any feedback you or others have:
>>
>> http://www.cactusflower.org/learning-flash-with-haxe
>>
>> Thanks
> more people might find it if you linked to it from the haxe wiki.
> http://haxe.org/doc/flash
>
> --
> haXe - an open source web programming language
> http://haxe.org


--
haXe - an open source web programming language
http://haxe.org