Created
September 17, 2014 12:59
-
-
Save markknol/4c2870d625587bc597be to your computer and use it in GitHub Desktop.
Native alert/prompt/confirm message for Flambe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package temple.utils; | |
import flambe.System; | |
/** | |
* @author Mark Knol [http://blog.stroep.nl] | |
*/ | |
class ExternalUtil | |
{ | |
#if air | |
public static var airBrowser:AirBrowser = new AirBrowser(); | |
#end | |
public inline static function alert(message:String) | |
{ | |
#if air | |
airBrowser.alert(message); | |
#else | |
System.external.call("alert", [message]); | |
#end | |
} | |
public inline static function prompt(message:String, defaultValue:String = null) :String | |
{ | |
#if air | |
return airBrowser.prompt(message, defaultValue); | |
#else | |
return System.external.call("prompt", [message, defaultValue]); | |
#end | |
} | |
public inline static function confirm(message:String) :Bool | |
{ | |
#if air | |
return airBrowser.confirm(message); | |
#else | |
return System.external.call("confirm", [message]); | |
#end | |
} | |
} | |
#if air | |
class AirBrowser | |
{ | |
var _html:flash.html.HTMLLoader; | |
public function new() | |
{ | |
_html = new flash.html.HTMLLoader(); | |
_html.loadString("<!DOCTYPE html><html lang='en'><head><meta charset='utf-8'><title></title><script></script></head><body></body></html>"); | |
} | |
public function alert(message:String) | |
{ | |
_html.window.alert(message); | |
} | |
public function confirm(message:String):Bool | |
{ | |
return _html.window.confirm(message); | |
} | |
public function prompt(message:String, defaultValue:String):String | |
{ | |
return _html.window.prompt(message, defaultValue); | |
} | |
} | |
#end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment