added loader sample

This commit is contained in:
2015-07-14 12:25:17 +03:00
parent 95ab956ea3
commit 61b0078f3f
7 changed files with 55 additions and 2 deletions

5
samples/02-loader/build.hxml Executable file
View File

@@ -0,0 +1,5 @@
-cp src
-lib haxework
-main LoaderExample.hx
-swf-version 10.1
-swf target/LoaderExample.swf

View File

@@ -0,0 +1,43 @@
package;
import flash.display.Bitmap;
import flash.Lib;
import flash.display.BitmapData;
import haxework.net.ImageLoader;
import haxework.net.JsonLoader;
typedef ChannelItem = {
var id:String;
var maker:String;
var title:String;
var message:String;
}
class LoaderExample {
public static function main() {
// Json
trace("Json Request");
new JsonLoader().GET("http://umix.tv/channel/data2/renova.json")
.success(function(channel:Array<ChannelItem>) {
trace("Json Ok: " + channel.length);
for (item in channel) {
trace(item.id + ": " + item.message);
}
})
.fail(function(error) {
trace(error);
});
// Image
trace("Image Request");
new ImageLoader().GET("http://umix.tv/channel/block/renova/1")
.success(function(image:BitmapData) {
trace("Image Ok: " + image.width + "x" + image.height);
Lib.current.addChild(new Bitmap(image));
})
.fail(function(error) {
trace(error);
});
}
}