Hey there !
I’m make some test with openFl and i’m not sure to understand the philosophy behind the Assets.loadImage, font, etc.
I make a new openFl project with this configuration :
<?xml version="1.0" encoding="utf-8"?>
<project>
<!-- NMML reference: https://gist.github.com/1763850 -->
<!-- metadata, make sure 'package' is at least 3 segments (ie. com.mycompany.myproject) -->
<meta title="LoadingTest" package="LoadingTest" version="1.0.0" company="" />
<!-- output -->
<app main="Main" file="LoadingTest" path="bin" />
<window background="#000000" fps="60" />
<window width="800" height="480" unless="mobile" />
<window orientation="landscape" vsync="false" antialiasing="0" if="cpp" />
<!-- classpath, haxe libs -->
<source path="src" />
<haxelib name="openfl" />
<haxelib name="actuate" />
<!-- assets -->
<icon path="assets/openfl.svg" />
<assets path="assets/img" rename="img"/>
<!-- optimize output
<haxeflag name="-dce full" /> -->
</project>
So I understand that all assets in assets/img are embbed and can use it with Assets.getImage(“img/elephant.jpg”) (or other) with the rename path Assets/img to only img/
But if i want to load other files asynchronously, and not necessary in “assets/img”. how make this properly ? (like no-embbed assets or an external assets). Need to use UrlLoader.hx or other class like this ?
I try to use Assets.loadImage(“Assets/other/elephant.jpg”), but seems to load only files into “assets/img”. Other path throw an error (like “assets/other/elephant.jpg” for exemple.) saying “file not found” to resume.
And this code find the file but throw an error :
package;
import openfl.display.Loader;
import openfl.display.Sprite;
import openfl.Lib;
import openfl.Assets;
import openfl.display.BitmapData;
import openfl.display.Bitmap;
import openfl.net.URLLoader;
/**
* ...
*/
class Main extends Sprite
{
public function new()
{
super();
var test = Assets.loadBitmapData("img/elephant.jpg");
test.onError(onError);
test.onProgress(onprogress);
test.onComplete(onLoaded);
}
private function onprogress(a : Int, b : Int) : Void
{
trace (a + "/" + b);
}
private function onError(test : Dynamic) : Void
{
trace(test);
}
private function onLoaded(bmd : BitmapData) : Void
{
var bm : Bitmap = new Bitmap(bmd);
this.addChild(bm);
}
}
The error throw By Lime.AssetsLibrary.hx (sorry, french version :p)
[Fault] exception, information=TypeError: Error #1034: Echec de la contrainte de type : conversion de __ASSET__img_elephant_jpg@3f10341 en lime.graphics.Image impossible.
Why this error ?
How to manage external/not embbed assets properly ?
There are a limit to embbed assets ? (like a max Cache size, or other limitation ?)
I’m using :
- haxe 3.4.3
- lime 5.7.1
- openfl 6.2.2
- actuate 1.8.7
Targetting Flash (for test only i want to targetting android and html5 soon)
Thanks and sorry for my bad english !