Importing / using classes in markup

#1

Hi Ian,

I am long time Adobe flashbuilder dev.
I love your work on HaxeUI.
I am trying to do proof of concept so I can look at doing project/development on HaxeUI.

In a mark up, I have declared a handler and am trying to do some http reqursts.
I seem to be getting stuck in simply referring to haxe.Http class.
I’ve tried an ‘import haxe.Http’ at the top of the script,
I tried using the module/scriptlet to load the class as a resource.
No go.
When I run/debug with flash player is says variable ‘Http’ is not valid.
eg.


//import haxe.Http;

	function doload(dummy) {
	   Screen.instance.messageDialog('test1', 'Dialog window'); 
	   var http = new Http("http://localhost:3339/status");
         ...

NOTE: When I used the same code in the Main.hx before the markup is loaded it works fine.
I know the even is firing since the dialog is poppup up.

Help please?

Thanks
Javy

#2

Hi, so i was just about to write how to do this using a module.xml and realised that when i tried to do it myself in a test project it wasnt actually working, so i think there is a bug somewhere. So need to do some digging - are you using the master branch or new-component-method?

Cheers,
Ian

#3

Hi Ian,
Thanks for quick reply.
I spent a couple of hours yesterday and got something working - basically figured out that using a module.xml let’s me declare a class which would then be available in the scripts running withing a markup. (I finally found how to use the module.xml from the sample 4.4.2.2.2.2_SimpleScriptWithImport example from github.)

For the benefit of others, here’s what I did:
file MyGet.hx:

package ;
import haxe.ui.core.Screen;

import haxe.Http;
class MyGet {
    public static function get(url: String) {
		var ghttp = new Http(url);
		Screen.instance.messageDialog('hello2', 'myGet'); 
               ghttp.onData = function (data:String) {
		     Screen.instance.messageDialog(data, 'myGet'); 
              }
	     ghttp.request();
			
    }
}

module.xml:

<?xml version="1.0" encoding="utf-8" ?>
<module>
    <scriptlets>
        <import class="MyGet" keep="true" static="true"/>
    </scriptlets>
</module>

and in my main.xml:

function doload(dummy) {
    Screen.instance.messageDialog('test1', 'doload'); 
    MyGet.get("https://api.ipify.org?format=json");
     Screen.instance.messageDialog('test2', 'doload'); 
}

Tested using html5 on Mac.

The original project I was experimenting with was this one:
4_ExtLib/4.4_GuiFrameworks/4.4.2_HaxeUI/4.4.2.1_SimpleGui/4.4.2.1.2_HaxeUIApp

So I am not sure if this is a master or new-component-method.
What I was trying to do was inside a click event, do some http access.
So I expanded the example to add my http object and request inside the main.xml markup.

For now I’ve created a http class which I was able to import via modules.xml and use in the script.
Which I realise is better since the strict compiler and type checking benefit will come from coding the ‘meat’ in the .hx files and then referring to them in the dynamic script code within markups.

One thing that would help a lot - and I am unsure if its what I am doing or perhaps choice of target.
Right now any runtime error in a script within the markup is not visible to me.
I am testing with html5 target on Mac.
On Friday I was also working on my PC dev using flash and neko targets - those appeared the same.
This is why I have got all the screen dialogs in the code - my crude method to figure out if the line in code has been reached.
So - if where any way to get runtime errors (or even script compile errors) showing up anywhere?
Log file, screen alert, exception within the .hx app etc.?

Cheers
Javy

#4

Ok, great you’ve found a work around. Im still looking at why you cant just import haxe.Http via a module.xml… For the errors in the script, can you provide an example of where it isnt showing the errors? I seem to get them, but maybe my test is different.

Cheers,
Ian

#5

Ok. ive managed to work out why you couldnt just use haxe.Http in the <import> node. Im going to fix it in the new-component-method branch. Do you know how to switch git branches in haxelib? Basically you would need to use the new-component-method branch of both haxe-core and whatever backend you are using (haxeui-openfl for example)

#6

Hi Ian,

I’m very new on haxe scene, only got first serious test/proof-of-concept last week, so any tips etc on setting up env and using the new-component-method etc would be helpful. Also new to git (been svn user and just started using git)

I have both a Mac dev env (primarily I used at home office to cut iOS builds) and PC dev env at office (where I do most of my development).

On Mac and PC, I’ve only used the straight haxe 3.X installer (and then haxelib install to put in other dependencies - openfl, haxeui-core etc).
On Mac I was using VS Code (since FlashDevelop is PC only).
I did try to switch to Haxe 4 rc1 on the Mac, but immediately got compile time errors from the haxeui-core area. (I was trying this as the haxe.org site was say the VS Code integration was much better).

Would appreciate your tips/recommendations for this env if you have any - ie should I stick to Haxe 3.x or switch to Haxe 4?
If 4,what do I need to change/set to get haxeui stuff to compile.
I suspect its some sort of lib thing, or needing to grab a version from git or similar.

On my PC, FlashDevelop seems to be the choice (closer to the FlashBuilder env I’ve been using for 10 years or so). I haven’t even tried Haxe 4 on that.
If I should use that, again whats the recommended method to get the env right for builing?

My main targets is business/cloud front end systems - so targets I see are html5 for easiest cloud support for our light weight clients apps/UIs and possibly native exes for PC and Mac for the heavier weight apps.

Your help is appreciated while I’m getting my sea legs in this new env. It’s pretty exciting. Today I was telling one of my long time developers about it - going to show him the tool kits to he can tinker.
Anyway - thanks.
cheers
Javy

#7

Ok, cool. Yeah, I can tell you how i set my environment up and it maybe help somewhat. So, to start with, i checkout haxeui-core and haxeui-html5 (could be any of the backends, but ill just use these two for descriptive purposes). So then i have something like:

C:\HaxeUI\haxeui-core\ and C:\HaxeUI\backends\haxeui-html5 (obviously these could be anywhere), so then i use the following commands to tell haxe to use these locations for the haxelibs, eg:

haxelib dev haxeui-core C:\HaxeUI\haxeui-core\
haxelib dev haxeui-html5 C:\HaxeUI\backends\haxeui-html5

So basically, now you are using the git versions of those libs as haxelibs (master branch), so finally now you need switch branch to new-component-method, you can do this on the command line with something like:

git checkout new-component-method
git branch

(you’d need to do this on each of the folders). An alternative (and something i do) is to use a git client - i use GitKraken. The process is basically the same, use that to checkout haxeui parts somewhere (or if you already have via the command line you can just open them)… Then you should be able to just switch branches in the GUI:

image

Note, that when we are talking about new-component-method you’ll need that branch for both the core and whatever backend you are working on. Eventually this branch will become master, and will be the official haxelib version, but its not quite ready yet.

This version should work on haxe3 or haxe4-rc1 (im using rc1, but 3 should also be fine).

Hopefully that will help a little, and fire away if ive missed something, or confused something.

Cheers,
Ian