I’m trying to implement Spil api into my flash game (made with haxeFlixel) and it works fine locally, but launching the game on any site causes errors while loading api and some of its files are not loaded.
I tried doing the same thing with an as3 project and there were no problems. I have no idea what it can be caused by, the process of implementing is rather simple ( http://developers.spilgames.com/wiki/Developer_Platform_-Learning_center-_Flash_API_get_started).
I know one example of successful implementation of this api but it was done with NME and so far I’m doing everything the same way.
Here is a link: http://www8.agame.com/mirror/QA-test/Flash/Cloudventure.swf
It says “URL not found”, I’m not sure what it’s trying to load, where? Do you have any way of guessing what it’s trying to load?
Which one says URL not found? Both links are still working for me. Here is another link to the game: https://dl.dropboxusercontent.com/u/68423650/Cloudventure.swf
It’s trying to load api files from the Spil server.
Here is what one of the errors looks like:
ReferenceError: Error #1065: Variable is not defined.
Oh, it was a Flash runtime error I got.
It’s too bad this isn’t open-source, or we would be able to understand what it’s trying to do, and issue a fix. As it is, I’m not sure if we would be able to do more without contacting their developer support, and getting some more insight into what their library is expecting here.
My guess is that it’s looking for a class that’s not available globally, either this is how their lib is included, or dead-code-elimination is removing some type it’s looking for?
Well, there is a way to download their swf from the server and decompile it (which I did) but it didn’t make it clear for me. I contacted their support, but so far they have no idea what’s going on too.
Tried adding haxedef name="-dce no" - didn’t help.
Any reason why it would work with an as3 project but not with an openFl one?
I’m not sure, the way the SWF is constructed may be a bit different (the way we push assets to another frame to support a preloader within the same SWF, so on) so it’s difficult to tell without knowing what definition it is trying to load. Perhaps we need to force a class into the SWF during compilation, perhaps it’s a matter of what applicationDomain is being used.
I seem to recall a fix that was in ApplicationMain.hx, which set the applicationDomain of something, after preloading was complete. I’m having trouble finding it. Not sure if this would be necessary/related to the issue
Got a reply from their support:
The SDK fetches 3 swf from our servers, I saw that in the game 2 are downloaded by the initialization, but the last one is not. The error that you sent is related to the missing file that is not downloaded.
You can look in the browser network for the files, they live in the following urls:
they are all loaded using a Loader class instance from Flash.
To me it seems the cause of one of them not loading is the first error, which has something to do with parsing an xml.
Not sure it has something to do with applicationDomain, could you explain, please? That’s how the first swf is loaded:
_context = new LoaderContext(false, ApplicationDomain.currentDomain); if (Security.sandboxType == Security.REMOTE) _context.securityDomain = SecurityDomain.currentDomain; _loader = new Loader(); _loader.load(_request, _context);
Perhaps we could try to recreate some of that manually in an OpenFL project, I wonder if it would exhibit the same errors?
Actually, it seems not to be connected to openFl by itself. I tried making a simple openFl project and everything worked (should have checked it long ago! >__<"). HaxeFlixel demos worked fine with the api as well. I’m still figuring out what part of my project is causing the problem.
Thank you for your time! I’ll write about the result when I figure it out.
Definitely interested to hear what you find, always glad to do what we can to make sure as much as possible works right out of the box. Unless it’s something simpler, perhaps the sandbox type or the application domain could be related, but like you say, it’s just as simple as loading an XML, or checking for crossdomain.xml in the loader context.
I mentioned the application domain earlier, because the “domain” is like a Map, which stores class and symbol references. If one SWF is expecting to find a class that’s defined in a different application domain, then it would not be able to find it, even though both were loaded.
I think I found the cause and it’s about the way I load info for fonts:
var textData = Assets.getText(“assets/fonts/londrina41.fnt”);
var xmlData = Xml.parse(textData);
So after I parse an xml in my code, the api can’t parse its xml… Why can this happen? Will investigate later (time to sleep!).
Yes, definitely the problem appears after using Xml.parse
I made a sample project just in case.
Test swf: https://dl.dropboxusercontent.com/u/68423650/ActuateExample.swf
I hope there is a way to solve this, I have no idea though.
I wonder if there is a class conflict where it affects the use of the Flash Xml class by name.
Or perhaps, looking at the source, perhaps this is a matter of setting the static ignoreWhitespace, ignoreComments and other Flash XML settings, you could check the before and after when using the class
Yes, you were right about setting the static ignoreWhitespace, ignoreComments and other Flash XML settings. After adding after using the function
XML.ignoreWhitespace = true; XML.ignoreProcessingInstructions = true; XML.ignoreComments = true;
there are no more errors. Yay! Thank you! So maybe this settings should be added at the end of a parsing function in the class? Perhaps I should report an issue there.
Yes, I would probably report it in both places. It may be safer for the Haxe function reset the values to their defaults (or to whatever they were set to before?)
…but with Spil, I would recommend telling them about this, so they can set the settings for XML to what they need in order to process their XML properly, as this could impact other developers that use different XML settings