{"id":522,"date":"2023-04-21T22:32:25","date_gmt":"2023-04-21T22:32:25","guid":{"rendered":"https:\/\/www.confidant.ca\/blog\/?p=522"},"modified":"2023-04-21T22:33:49","modified_gmt":"2023-04-21T22:33:49","slug":"triggering-haxe-functions-from-within-openfl-textfield-html-links","status":"publish","type":"post","link":"https:\/\/www.confidant.ca\/blog\/2023\/triggering-haxe-functions-from-within-openfl-textfield-html-links\/","title":{"rendered":"Triggering Haxe functions from within OpenFL TextField HTML links"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">It&#8217;s been a while since I posted anything useful (not sure if I ever have) but anyway here&#8217;s a tip for the Haxe \/ OpenFL coders out there. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var walkThruText = new TextField(); \/\/or new Label();\nwalkThruText.htmlText = 'Want a walkthrough on how to use the tool?&lt;br \/>&lt;font color=\"#0000ff\">&lt;a href=\"event:tutorialClick\">Watch this short tutorial&lt;\/a>&lt;\/font> to become an expert.';\n\nwalkThruText.addEventListener(TextEvent.LINK, (linkEvent:TextEvent)->{\n\tswitch (linkEvent.text){\n\t\tcase \"tutorialClick\":\n\t\t\ttrace(\"You clicked the link!\");\n\t}\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So the secret is to add an event with a name as the href on the &lt;a&gt; tag, then listen for the TextEvent when it gets clicked. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bonus tip: text formatting within a TextField can be applied by either using the &#8220;setTextFormat&#8221; method on a text field and providing a start\/end range, or you can use various html tags as <a href=\"https:\/\/help.adobe.com\/en_US\/FlashPlatform\/reference\/actionscript\/3\/flash\/text\/TextField.html#htmlText\" target=\"_blank\" rel=\"noreferrer noopener\">listed here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I hope this helps someone!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s been a while since I posted anything useful (not sure if I ever have) but anyway here&#8217;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. &hellip; <a href=\"https:\/\/www.confidant.ca\/blog\/2023\/triggering-haxe-functions-from-within-openfl-textfield-html-links\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Triggering Haxe functions from within OpenFL TextField HTML links<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[3],"tags":[6,38],"class_list":["post-522","post","type-post","status-publish","format-standard","hentry","category-development","tag-haxe","tag-openfl"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p28GE6-8q","_links":{"self":[{"href":"https:\/\/www.confidant.ca\/blog\/wp-json\/wp\/v2\/posts\/522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.confidant.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.confidant.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.confidant.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.confidant.ca\/blog\/wp-json\/wp\/v2\/comments?post=522"}],"version-history":[{"count":2,"href":"https:\/\/www.confidant.ca\/blog\/wp-json\/wp\/v2\/posts\/522\/revisions"}],"predecessor-version":[{"id":524,"href":"https:\/\/www.confidant.ca\/blog\/wp-json\/wp\/v2\/posts\/522\/revisions\/524"}],"wp:attachment":[{"href":"https:\/\/www.confidant.ca\/blog\/wp-json\/wp\/v2\/media?parent=522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.confidant.ca\/blog\/wp-json\/wp\/v2\/categories?post=522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.confidant.ca\/blog\/wp-json\/wp\/v2\/tags?post=522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}