Need help for convert my code AS3 to Haxe

268 views
Skip to first unread message

Cédric Besse

unread,
Aug 15, 2016, 9:16:02 PM8/15/16
to Haxe
Hello,

I have spent my day to look for correspondences between my AS3 code and Haxe.

I understand my code in AS3, but I have problem with Haxe syntax to convert.

For example my line redirection for it opens in the same window:

navigateToURL(new URLRequest(String("http://www.mysite.com/jeux/profile/") + String(_Value)),"_self");

To:

flash.Lib.getURL(new flash.net.URLRequest("http://www.mysite.com/jeux/profile/"));

I had to replace in imports

import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequestMethod;

By:

import flash.events.Event;
import flash.Lib;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.Lib.getURL;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequestMethod;

navigateToURL posed a problem, so I replaced it by import flash.Lib.getURLTo use the function URLRequest()

But I can't find the correct syntax to add my variable in the url _Value and also the _self for the redirect is done in the same window ...


For my variables as this is a game I wanted to spend my variables from a form to my flash game using the basic AS3

var _Value:String = LoaderInfo(FlxG.stage.root.loaderInfo).parameters.pseudo;
var _Game:String = LoaderInfo(FlxG.stage.root.loaderInfo).parameters.game;

But in Haxe I'm really lost for the moment...

The rest of my code: to process and send the information:

var urlLoader:URLLoader = new URLLoader();

var urlRequest:URLRequest = new URLRequest("http://www.mysite.com/jeux/test.php");
urlRequest.method = URLRequestMethod.POST; 

var urlVariables:URLVariables = new URLVariables();
urlVariables._Game = LoaderInfo(FlxG.stage.root.loaderInfo).parameters.game;
urlVariables.Score = Score;
urlRequest.data = urlVariables;

urlLoader.addEventListener(Event.COMPLETE, donneesChargees);
urlLoader.load(urlRequest);

function donneesChargees(e:Event):void
{
_tf = (e.target as URLLoader).data;
}

I have seen information about URLLoader but I never found a concrete example to help me ...

So if a charitable soul could help me understand and convert my code ends, it would be really nice.

I'm really sorry for my English, because I'm French.

Thank you so much

Yoni Gueta

unread,
Aug 16, 2016, 6:24:45 AM8/16/16
to Haxe


the "parameters" field is of type Dynamic<String>, you can modify a Dynamic type like this: 

Alexander Kuzmenko

unread,
Aug 16, 2016, 2:29:49 PM8/16/16
to Haxe
Have you seen this ? http://lib.haxe.org/p/as3hx/

вторник, 16 августа 2016 г., 4:16:02 UTC+3 пользователь Cédric Besse написал:

Cédric Besse

unread,
Aug 17, 2016, 4:50:23 AM8/17/16
to Haxe
Thank you so much Yoni !

Thanks to your example I was able to retrieve the variables in this way:
var _Game:String =  flash.Lib.current.stage.loaderInfo.parameters.game;



Message has been deleted

Cédric Besse

unread,
Aug 17, 2016, 4:54:58 AM8/17/16
to Haxe
Thank you too Alexander, I tried to use a converter to Haxe AS3, but I have not managed to understand how to use ...
Message has been deleted

Cédric Besse

unread,
Aug 17, 2016, 5:08:45 AM8/17/16
to Haxe
This leaves me currently 2 problems:

To send my data here's what I have done but I have an error message in this new code:
var urlRequest = new URLRequest("http://www.mysite.com/jeux/test.php");
urlRequest.method = URLRequestMethod.POST;

var urlVariables = new URLVariables();
urlVariables._Game = flash.Lib.current.stage.loaderInfo.parameters.game;
urlVariables.popCount = (getGameAttribute("Score"));
urlRequest.data = urlVariables;

var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, fetchData);
urlLoader.load(urlRequest);

function fetchData(e:Event):Void
{
        var urlLoader:URLLoader = cast e.target;
        urlLoader.removeEventListener(Event.COMPLETE, fetchData);
        trace (urlLoader.data); 


And

By cons to redirect a URL in the same window using _self I have found encpre example for syntax. Same to insert a variable in the URL:
Base:

navigateToURL(new URLRequest(String("http://www.mysite.com/jeux/profile/") + String(_Value)),"_self");

New:
flash.Lib.getURL(new flash.net.URLRequest("http://www.mysite.com/jeux/profile/"), ???);

As saith the french proverb, " Je pédale dans la semoule" ^^

Thank you.

Alexander Kuzmenko

unread,
Aug 17, 2016, 5:19:38 AM8/17/16
to Haxe
Well, it should be something like this in command line: 
haxelib install as3hx
haxelib run as3hx as3sources_directory
/ output_directory/



среда, 17 августа 2016 г., 11:54:58 UTC+3 пользователь Cédric Besse написал:

Simon Krajewski

unread,
Aug 17, 2016, 5:45:59 AM8/17/16
to haxe...@googlegroups.com
Am 17.08.2016 um 11:19 schrieb Alexander Kuzmenko:
Well, it should be something like this in command line: 
haxelib install as3hx
haxelib run as3hx as3sources_directory
/ output_directory/

Note that you probably want to use the current git version of as3hx because it's being greatly improved by SlavaRa.

Simon

Cédric Besse

unread,
Aug 18, 2016, 9:58:54 PM8/18/16
to Haxe
Hello and thank you so much.

I tried as3hx

But I came across an error message:
ERRORS: These files were not written due to source parsing errors: In c:/Users/Cudric/as3sources_directory/test.as(2) : Unexpected if

I used the example of the link in my test.ashttps://github.com/HaxeFoundation/as3hx

if (true) {
   
for (var i:uint = 0; i < 7; i++)
        val
+= "0";
} else {
   
for (i = 0; i < 8; i++)
        val
+= "0";
}


Mark Knol

unread,
Aug 19, 2016, 8:51:41 AM8/19/16
to Haxe
Isn't that exactly what is described in the "current failures" section?

Cédric Besse

unread,
Aug 19, 2016, 7:58:34 PM8/19/16
to Haxe
I have succeeded in do the conversion, thank you!!! :)

But I get an error message in the code:
Unexpected catch

import flash.events.Event;
import flash.Lib;
import haxe.DynamicAccess;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLLoader;
import flash.Lib.getURL;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequestMethod;


class Test {

    private var urlLoader : URLLoader = new URLLoader();
    
    private var urlRequest : URLRequest = new URLRequest("http://www.mysite.com/jeux/test.php");
    
    private var urlVariables : URLVariables = new URLVariables();
    

    private function donneesChargees(e : Event) : Void
    {
        donneesChargees = (try catch(e:Dynamic) cast(e.target, URLLoader) null).data;
    }


    private static var init = {
        urlRequest.method = URLRequestMethod.POST;
        urlVariables._Game = cast((FlxG.stage.root.loaderInfo), LoaderInfo).parameters.game;
        urlVariables.popCount = (getGameAttribute("Score"));

Philippe Elsass

unread,
Aug 20, 2016, 5:41:25 PM8/20/16
to Haxe
There is quite obviously incorrectly generated code:
(try catch(e:Dynamic) cast(e.target, URLLoader) null).data

It's a failed attempt to converting (e.target as URLLoader) - this should be reported as a bug of as3hx.

You can rewrite that as: (cast(e.target, URLLoader).data

Philippe


--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.



--
Philippe

Cédric Besse

unread,
Aug 23, 2016, 12:46:07 PM8/23/16
to Haxe
Perfect, thank you very much to all for your help! :)
Reply all
Reply to author
Forward
0 new messages