Triggering Haxe functions from within OpenFL TextField HTML links

It’s been a while since I posted anything useful (not sure if I ever have) but anyway here’s a tip for the Haxe / OpenFL coders out there.

Sometimes you need to have responsive, flowing text in your application and still use it to trigger functions, just like a webpage. So here is the solution. This works with a regular OpenFL text field, or a Label in FeathersUI.

var walkThruText = new TextField(); //or new Label();
walkThruText.htmlText = 'Want a walkthrough on how to use the tool?<br /><font color="#0000ff"><a href="event:tutorialClick">Watch this short tutorial</a></font> to become an expert.';

walkThruText.addEventListener(TextEvent.LINK, (linkEvent:TextEvent)->{
	switch (linkEvent.text){
		case "tutorialClick":
			trace("You clicked the link!");
	}
});

So the secret is to add an event with a name as the href on the <a> tag, then listen for the TextEvent when it gets clicked.

Bonus tip: text formatting within a TextField can be applied by either using the “setTextFormat” method on a text field and providing a start/end range, or you can use various html tags as listed here.

I hope this helps someone!

Adobe: Why no AS3/HTML5 solution for Flash?

Every time Adobe does an article about the Flash IDE’s ability to do HTML5, I am very interested and I check it out. I am always disappointed when they get back to the fact that you have to use JavaScript.

I really cannot understand why Adobe has not endorsed or offered a method to compile Actionscript (or a better language) to JavaScript from within the Flash IDE. Actionscript 3 is clearly superior to JavaScript. Why should we have to re-write everything when we’re in the same IDE? Why are they taking a step backwards?

I would consider Haxe to be the ultimate solution, but Adobe could even use Jangaroo or similar technology to target HTML5—maybe even bundle Google Swiffy. If they did, I’m sure developers would be happy to be able to create both Adobe AIR apps and HTML5 apps from the same code base without needing to install other tools. Those of us using Haxe are already basking in the glory of that.

Perhaps Adobe thinks such a move would eat away at their AIR platform’s popularity. I just don’t know why they bother with JavaScript tools within Flash, when better tools exist. As it stands, I expect that more developers will be doing like I did and begin switching to Haxe with OpenFL, which is a more advanced language than AS3 and can compile to SWF/AIR, HTML5, and a host of other desktop, console and mobile platforms.