Skip to content

Instantly share code, notes, and snippets.

@droidalex droidalex/Banner.hx
Created Sep 21, 2016

Embed
What would you like to do?
Simple Banner
package;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.text.FlxText;
import flixel.ui.FlxButton;
import flixel.math.FlxMath;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import haxe.crypto.Base64;
import haxe.io.Bytes;
import sys.io.FileOutput;
import flixel.input.mouse.FlxMouseEventManager;
import openfl.Lib;
class Banner extends FlxSprite
{
public var url_dest:String;
public var url_img:String;
function onMouseUp(sprite:FlxSprite)
{
Lib.getURL (new URLRequest(url_dest));
}
override public function new(x:Float,y:Float,width:Float,height:Float,url_img,url_dest):Void
{
super();
this.x=x;
this.y=y;
this.width=width;
this.height=height;
this.url_dest=url_dest;
this.url_img=url_img;
var image_Loader = new Loader();
image_Loader.load(new URLRequest(url_img));
image_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
image_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
}
public function onLoaded(e:Event):Void
{
get_It(Base64.encode(e.target.data));
}
public function get_It(img64:String)
{
var arq = "assets/data/banner.jpg";
var bb:Bytes = Base64.decode(img64);
var fo:FileOutput = sys.io.File.write(arq, true);
fo.write(bb);
fo.close();
}
public function onComplete(e:Event):Void
{
try
{
this.loadGraphic("assets/data/banner.jpg");
FlxMouseEventManager.add(this, onMouseUp);
}
catch( msg : String )
{
trace("Error message : " + msg );
}
}
}
package;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.text.FlxText;
import flixel.ui.FlxButton;
import flixel.math.FlxMath;
class MenuState extends FlxState
{
private var banner:Banner;
override public function create():Void
{
super.create();
//------- This can be usefull with rotating banners.
//------- Parameters: x, y, width, height, url-image, url-destination
banner = new Banner(10,10,400,400,"https://cex.io/widget/dark/300/btc-usd","http://www.bing.com/search?q=haxeflxel");
add(banner);
}
override public function update(elapsed:Float):Void
{
super.update(elapsed);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.