How do we embed FGL API in haxe ?

13 posts (showing 1-13)
Panthenol

Market Level 0Community Level 7
579 posts

Sorry to ask something that might be obvious for a lot of folks here :

How do we embed FGL SDK in haxe ?

Once i did exactly what was said in this thread

https://www.fgl.com/view_thread.php?thread_id=49431   (awesome post by b10b)

 I can't call any FGL sdk  javascript functions:

[Haxe]
public function initFGL() {
#if js untyped fgl.FGLImplementationTestingSDK(); #end // or any other function
}[/Haxe]

 

once compiled and running in chrome, console says " Uncaught ReferenceError: fgl is not defined "

altrough i have fgl.js present in /source and /assets folders

maybe i'd have to change the Project.xml file ?                                                                                         any help would be appreciated , as Haxe seems to be a great development language

posted 2015-01-12T13:46:23-08:00 | edited 2015-02-04T22:05:55-08:00
b10b

Market Level 4Community Level 7
971 posts

Perhaps the FGL SDK is not loaded in the html?  e.g. double check this, or similar, exists:

<script src="fgl.js"></script>

If using OpenFL you might need to edit your templates, else the html file will be overwritten each build (and this will be removed).

posted 2015-01-12T17:02:42-08:00 | edited 2015-01-12T17:03:11-08:00
FGL_Porter

FGL AdminCommunity Level 16
427 posts

As b10b said, I had a go at getting this to work, and I had to manually add <script src="fgl.js"></script> to the output html file.

I didn't read through the thread you linked, but I used a class with static public functions to make things easier. I had a class named FGL, which you can get here. After you compile, close the file, add the script to the .html file, launch, and all of your calls to FGL.showAd() and so on will work. Note, that my fgl.js file was located in bin/html5/bin/lib/fgl.js, though I don't recall the exact reason I put it there.

I've read there are ways to ensure your html file doesn't get overwritten when you compile, but I haven't looked into the details yet.

posted 2015-01-12T17:26:28-08:00 | edited 2015-01-12T17:31:06-08:00
Panthenol

Market Level 0Community Level 7
579 posts

Thanks guys ! i'm now trying to have Haxe output the correct html5 file

I have to work on several things on parallel, but i will update as soon as possible ! 

posted 2015-01-12T22:42:40-08:00
Panthenol

Market Level 0Community Level 7
579 posts

i think it's this template system , http://old.haxe.org/doc/cross/template

and we would use it to generate the index.html file ,

with fgl.js and fgl-scaler.js  embedded like b10b and  FGL_Porter described

but i don't see how to use it yet

in any haxe/javascript FlashDevelop project , there is no template file generated :/ 

posted 2015-01-13T15:46:59-08:00 | edited 2015-01-13T16:56:46-08:00
FGL_Porter

FGL AdminCommunity Level 16
427 posts

While I'd greatly prefer the template, keep in mind that the FGL SDK is pretty simple, and you can test it by manually adding those lines. It is annoying, but really only takes 10 seconds or so. The SDK itself isn't complicated, so everything you try to do should work on the first or second try, at least that was my experience.

posted 2015-01-13T16:04:13-08:00
b10b

Market Level 4Community Level 7
971 posts

I was referring to the OpenFL template that creates the index.html file in your bin output.  You can customize this by creating a new one in your /assets path and copying it at build.  Add this in your OpenFL project xml.

<template path="assets/templates/html5" rename="" if="html5" ></template>

So you'd have a templates/html5 folder in assets, containing an index.html file (and the fgl.js).  That index.html would be based on the default index.html but with the addition of:

<script src="fgl.js"></script>

I couldn't find documentation for this on the OpenFL site and I don't use OpenFL much, so forgive me if it's slightly wrong.

posted 2015-01-13T17:06:11-08:00 | edited 2015-01-13T17:06:54-08:00
FGL_Porter

FGL AdminCommunity Level 16
427 posts

So basically you'll always build your main template each compile, but you'll have an additional template with the FGL SDK that's included / applied to the base template if you compile to html5? That sounds like a proper solution to me.

posted 2015-01-13T17:18:33-08:00 | edited 2015-01-13T17:39:42-08:00
b10b

Market Level 4Community Level 7
971 posts

Yes, it should copy it each build, exactly like the build tool copies the audio and graphical assets.  Also, I don't think fgl-scaler is needed as iirc fullscreen scaling is handled within the latest OpenFL html5 backend.

posted 2015-01-13T17:36:29-08:00
Panthenol

Market Level 0Community Level 7
579 posts

briefly talked with some awesome haxe folks ( varIsNice )

and they are using command lines to create a custom html5 file at each compile

( with unix tho, without flashDevelop on unix ) 

so i'm thinking some command lines in Project/Properties/Build/

pre-build command lines/ post build command lines would do the trick

posted 2015-01-16T00:45:59-08:00 | edited 2015-01-16T21:03:11-08:00
failsafegames

Market Level 5Community Level 1
37 posts

If you are using OpenFL / Lime you can use

<dependency name="./fgl.js" if="html5" />

<template path="./dependency/fgl.js" rename="fgl.js" if="html5" />

Which will add the corresponding <script /> into your HTML and move the fgl.js to the bin folder.

I made a haxelib to make things easiers: https://github.com/starburst997/haxe-fgl

Simply add <haxelib name="haxe-fgl" /> and your good to go.

posted 2015-02-04T21:17:57-08:00
xmorpher

Market Level 3Community Level 5
538 posts

One question.... How do you handle the function: getBrandingLogo() in Haxe?

Since you receive a String with the url...

the image should be loaded into a BitMap with a Loader class...

or is there anything simplier than that?

posted 2015-02-09T14:26:17-08:00
failsafegames

Market Level 5Community Level 1
37 posts

I'm using OpenFL, here's a class I wrote for loading BitmapData over URL: https://gist.github.com/starburst997/166373ceb9daccbcbff7

Then you use something like this:

[as3]
if ( FGL.brandingEnabled() )
{
    BitmapLoader.loadFile( FGL.getBrandingLogo(), function( bmpd )
    {
        var bitmap = new Bitmap( bmpd );
        addChild( bitmap );
    }, true );
}[/as3]

 

posted 2015-02-09T17:54:11-08:00