added loader sample
This commit is contained in:
43
samples/02-loader/src/LoaderExample.hx
Executable file
43
samples/02-loader/src/LoaderExample.hx
Executable 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user