# navigateToURL for Openfl

I have a Flash background.
And I notice that I first think (or Google) what would the code be in Flash and then try to convert it to Haxe/Openfl

Same with:
<a href="open-link-in-new-window" target="_blank">

## AS3

var myURL:URLRequest = new URLRequest("open-link-in-new-window"); navigateToURL(myURL, "_blank");

## Openfl

var myURL:URLRequest = new URLRequest("open-link-in-new-window"); openfl.Lib.getURL(myURL, "_blank");

# Moving from FDT to MonoDevelop for haXe and NME

Before I start with this post I should mention that Joshua Granick (on of the creators of NME) has a post about:How to Install Haxe, NME and MonoDevelop! That will save me some time and who can explain that better than Joshua.

I wrote something similar when I moved from PC (FlashDevelop) to OSX (FDT) (read my post: moving-from-flashdevelop-to-fdt/). Which also was a reminder when I needed to reinstall or explain it to a college.

Want to know why I’m using MonoDevelop?
Moving from FDT to MonoDevelop is not a big step (my opinion 😛 )

After reading my post, it looks like I’m leaving FDT… That is not what I’m doing: I’ll keep on using it for AS3.
But I hope to ‘take’ some features from FDT to MonoDevelop

First let add some features that I use a lot:
MonoDevelop > Preferences... (CMD+,) > Key Bindings
search for “comment”
Toggle Line Comment : Edit Binding > (CMD + 7)
search for “case”
Uppercase Selection : Edit Binding > (CTRL + SHIFT + X)
Lowercase Selection : Edit Binding > (CTRL + SHIFT + Y)
search for “template”
Insert template.. : Edit Binding > (CMD + SHIFT + 1) [doesn’t work yet]

### Using default Short cuts – (besides the ‘normal’ short cuts)

Then there are some default shortcuts you use a lot:
run >> ALT + CMD + enter
debug >> CMD + enter (doesn’t work)
move the line or highlighted section down >> ALT + ARROWDOWN
move the line or highlighted section up >> ALT + ARROWUP
show completion window >> ALT + SPACE

Don’t have to explain this … right?
MonoDevelop > Preferences... (CMD+,) > Author Information

### Changing settings

Perhaps this is very personal, but I’m not writing this for you alone (it’s also a reminder to myself!)
MonoDevelop > Preferences... (CMD+,) > Text Editor > Behavior >

• check: Insert matching brace
• check: Smart semicolon placement
• check: Enable on the fly code formatting (doesn’t do anything)
• check: Format document on save (doesn’t do anything)

and
MonoDevelop > Preferences... (CMD+,) > Text Editor > Behavior > XML

• check all

Moving on:
MonoDevelop > Preferences... (CMD+,) > Text Editor > Syntax Highlighting
I installed Monokai for Darius Kucinskas: you can get it from github. That because I use it on TextMate and gotten use to it….
Joshua Granick has created a FlashDevelop color scheme (if there are people who want to move from PC to Mac/Linux).

### Templates/snippets

And then the most interesting… the one that doesn’t seems to be working
MonoDevelop > Preferences... (CMD+,) > Text Editor > Code Templates
Code templates are awesome and speed up your development a lot (create a getter/setter in just one click for example)
Just do the following:
Edit > Insert template...
And remember that the mime type is:
mime: text/x-haxe
It really doesn’t matter what you do… for example // test

but then only bugs…

🙁

### I would like to see

I miss some stuff that I was very use to, so lets make that a NICE-TO-HAVE-LIST

• feedback when exporting/compiling to a target like SublimeText 2 or in the terminal.
• code completion on variables and functions
• templates that work
• duplicate line (up/down)
• code formatting
• auto import
• code checking while typing/checking without running
• if auto code checking is not going to happen: a shortcut to check your code
• automatic “add to folder” (for all folders)

# FDT and ANT – part 2

Trying to build the ultimate build.xml in ANT: debug/production zip ftp version … etc: will save a lot of keystrokes in FDT4

All the information about the ultimate build.xml can be found on the internet, so I will post the links and you can figure it out for yourself.

I used the build.xml made by Jankees van Woezik (Base 42) as the base of my ultimate ANT build file. You can read about it and download here: My workflow with ANT and FDT.

Because we work a little bit different I had to do some modifications (for example: I work with 2 swf: preloader.swf and main.swf and work on PC). I created a list of stuff that I wanted to do with ANT and behind the “wish” you find a link to the site I found the solution for the problem:

1. base ant script >> http://blog.base42.nl/2009/12/11/my-workflow-with-ant-and-fdt/
3. install ftp protocol in fdt/eclips >> http://www.rumblingskies.com/blog/?p=75
4. update version ant script >> http://github.com/base42/projectcreator/blob/master/original/flash/builders/ant/updateVersionFile.xml
5. another update ant script >> http://www.sephiroth.it/weblog/archives/2010/01/update_your_app_version_using_ant_bui.php
6. update Firefox (only works on OSX) >> http://epologee.com/blog/2009/focus-and-reload-pages-in-firefox-with-ant/
7. html wrapper >> http://fdt.powerflasher.com/blog/?p=1392

Something like this needs some time to find its place in my workflow, and will be changed a lot. That is the reason why I’m not posting my ant file… not because it’s ugly or a secret… but because I need to refine it.

Oh… I also have a small todo list (perhaps you could call it a nice-to-have-list)

As you can see, these are the thing that I don’t need a lot, but perhaps in the nearby future…

### FTP (File transfer protocol)

Ant doesn’t have the FTP protocols default installed so you need to update FDT4/Eclipse.
You can find the explanation here: http://www.rumblingskies.com/blog/?p=75

Update #1:The locations of the files you need are changed so let me post the correct ones here:

Save these files in the following folder: C:\FDT\plugins\org.apache.ant_***\bin\

Update #2: hmmm jakarta-oro seems to be Retired… and I haven’t got time to figure this out right now…

You probably can add the zips you downloaded there, I extracted the two files and that worked for me. I did this in FDT4 and all I got was an alert about “The specified Ant runtime classpath does not include a tools.jar library…..” which I ignored (and without any problem).

After the installment of the two .JAR files you need an ANT script to get thing started which I just copied from the previous link:
[as light=”true” wraplines=”true”]
<ftp server="123.456.78.90"
port="21"
userid="my_user_id"
passive="no"
depends="yes"
binary="yes">
<fileset dir="../bin" />
</ftp>
</target>[/as]

### Update version

It’s a combination of writing a build.txt file and a Version.as file.
See what Jankees van Woezik did and I use the script from Sephiroth to have a building number that adds 1.

### Firefox refresh

this feature is awesome in combination with ftp, so here the one who found the how: Eric Paul (epologee). Read more about it here: focus-and-reload-pages-in-firefox-with-ant

So downloaded the file, installed the firefox extension and gave it a run:
[as light=”true” wraplines=”true”]
<target name="focus Firefox and reload page">Execute failed: java.io.IOException: Cannot run program "open" (in directory "C:\foo\bar\test"): CreateProcess error=2, Het systeem kan het opgegeven bestand niet vinden
[/as]

After some googling, I found that it’s a OSX command that doesn’t work on Windows:

[as highlight=”1″ light=”true” wraplines=”true”]
<target name="focus Firefox and reload page">
<exec executable="open">
<arg line="-a Firefox" />
</exec>
<exec executable="flash/tools/fresno/fresno">
</exec>
</target>[/as]

I haven’t found a solution that refreshes the page like Fresno does on Windows.
So the only thing I can think of is:

[as light=”true” wraplines=”true”]
<echo>Launch in Firefox (not really a reload)</echo>
<exec executable="H:/Program Files/Mozilla Firefox/firefox.exe" spawn="yes">
<arg line="${flashproject.preview.url}" /> </exec> </target> [/as] ### Html wrapper I changed the file a little bit (removed the history) not really difficult. ### Folders You get the idea…. (reminder for myself: http://fdt.powerflasher.de/docs/FDT_Ant_Tasks) # Create SWC library from FDT I use Greensock Tweening Platform a lot, it awesome. Download it (here for example) and you have everything you need. Now I start working with SWC files and they are so compact: I love it. But how do you get a library in a SWC? Google has an answer but it’s very complex. The best answer is from Bruno Fonzi on How to create SWC libraries from FDT: Right click Project > Run as > FDT Library or Menu > Run Configurations > Create new FDT Library So start with a New Flash Project (the name you will use for this project will be the name of the SWC: in my case “Greensock_Tweening_Platform”) and copy the com folder from the Greensock ZIP into the src (of source) folder. If you follow the instructions and create a SWC you will get an error about: UIComponent and Vector (depends on your Project properties). So to fix this: follow the 2 red x’s com > greensock > loading > display > FlexContentDisplay I don’t use this one, so delete. The next depends on the project properties (I used SDK: Flex 3.3 and Player Version 9 and there are no Vectors in Player version 9) com > greensock > plugins > EndVectorPlugin I can’t use this one, so delete this on too. Create the SWC again and your done: you have one file with the Greensock Tweening Platform in it. # FDT and ANT – part 1 Just started to work with FDT and wrote about my “troubles” (post#1 and post#2) with my transition from FlashDevelop. (have to be very carefull what I say: “they” are watching me: here and here 😀 ) And it seems to be a very natural (geeky) thing to learn about ANT. And where do you go to learn about ANT and SWF/Flash/FDT? (Google?) After some tinkering all I got was: failed to create task or type fdt.launch.application This post was very useful: FDT and ANT | A Users Guide Part I by Alan Klement. Watch the videos (I’m not very fond of tutorial videos but in this case; they get the job done). What I love about the “Video I: Getting Started” is the fact that it builds up from scratch. So watch this video when you want to know about ant-files/xml, how to open the ANT-View, how to open/execute an ANT-file. The second video (Video II: Compiling a SWF) was what I really was looking for: how to export a SWF. Very nice because it starts from scratch. And it gave me the answer I was looking for: why didn’t my ANT-file didn’t work (it about 3/4 of the video):  BUILD FAILED [blabla]\source\a\example\build\build.xml:17: Problem: failed to create task or type fdt.launch.application Cause: The name is undefined. Action: Check the spelling. Action: Check that any custom tasks/types have been declared. Action: Check that any / declarations have taken place.  Solution is very simple, but if you don’t know, you will hate FDT and really it’s not it fault: Goto the green “play” button with the brown bag, in the toolbar (one picture says more than a thousand words:) Select the ANT-file you want to change (I have only one :D), goto to tab “JRE” and change the Runtime JRE to Run in the same JRE as the workspace and your done: Very useful are the ANT-snippets and ANT-Build-template! Download (created by Alan Klement) and “install” the ANT-template (how-to on this page but here the short version) To add XML files templates go: Preferences > XML > XML Files > Editor > Templates and click import. To add Ant snippets go: Preferences > Ant > Editor > Templates and click import. I haven’t seen the second part of this tutorial: FDT and ANT | A Users Guide Part II but I will. It seems to be focused on the use of the templates and snippets. # Missing in FDT after working with FlashDevelop I love FlashDevelop but moved to FDT (read my other post about this subject)… Not an easy thing (the biggest problem is that it totally not intuitive ) to do and I’m missing some stuff that I had in FlashDevelop. CTRL+U to change the selected text to uppercase Update #1: I have found it: ToUpperCase = CTRL+SHIFT+X ToLowerCase = CTRL+SHIFT+Y CTRL+SHIFT+1 to “Promote member to class” (there is a similar way to do this in FDT but not the same) CTRL+SHIFT+Q to create a block comment It is in FDT but I can’t get it to work so you have to work with CTRL+7 (toggle comment) which is a minor adjustment. The auto-completing FlashDevelop is awesome!! With some tinkering (info here) you can get FDT in the same room but it’s still not the same. I’m used to write private variable with a prefix “_” (example: _variableName). When I want the variable name to autocomplete in FlashDevelop I just type variableName (without the “_” prefix because it stupidly positioned on the keyboard) and it will find it. In FDT you need to start with the prefix “_” otherwise it will ignore the variable name… why??? Also missing: Explore (Open “Project Manager” and right-click on a folder) (can’t find it in FDT) But I shouldn’t complain, there is a reason why I’m changing to FDT Big plus from FDT: CTRL+SHIFT+F to Format code which is not possible in Flashdevelop SWC Browsing is limited in FlashDevelop Cross Platform: FlashDevelop works only on Windows Refactor: this is so awesome (and expensive!!!) # Moving from FlashDevelop to FDT Yes, its time, I need to… So how to make the transition from FlashDevelop to FDT as easy as possible? ### Let FDT react like FlashDevelop And I don’t even have to break a sweat: the amazing Steven Sacks (creator of Gaia) wrote an article about it: read here. The only two thing that I’m using are: Open Window > Preferences Under FDT > Editor > Code Assist copy and paste this into Auto activation triggers for AS, and set the delay to 0ms (zero). abcdefghijklmnopqrstuvwxyz_. : and Under Problems > AS3 Problems: Unresolvable > Unresolvable variable reference in E4X and Unresolvable member reference in dynamic object should both be set to Disabled (from Warning to Disabled). The shortcuts I just left them as they where: I’m working in another program so I should use the shortcut given by that program. Update #1: hmmm I noticed that I can’t live without CTRL+ENTER…. explanation here: Using CTRL-ENTER to compile ActionScript code in FDT. So now I have CTRL+ENTER and debug run: CTRL+SHIFT+ENTER 😀 short explanation (so I can do this quickly if something happens to FDT): Under Preferences > Run/Debug > Launching at the bottom at Launch Operation: Select “Always launch the previously launched application then Under Preferences > General > Keys find (or type in “type filter text” – searchbox: “last”) a command called “Run Last Launched” and click Copy Command. Assign (binding) the shortcut CTRL-ENTER to the copied command and change “when” to Editing ActionScipt Source (no spelling mistake: it really says that) Editing ActionScript Source. Do the same thing for the “Debug Last Launched” command and assign the shortcut : CTRL-SHIFT-ENTER and change the when to Editing ActionScipt Source. I’m not sure if the stuff I wrote here is only for FDT4 but the way it was explained on the site previous mentioned didn’t work in FDT4 ### Some templates/snippets that are very useful I used this plugin for my trace in FlashDevelop, so how to do this in FDT? Update #2: I shouldn’t forget to mention CTRL+0 (read the shortcut list for FDT) which is the shortcut for “Quick Trace”. This one I use to trace variable for example and the trace template below for functions. Update #4: This is really a reminder for myself, but if you need it you know where you can find it in FDT4. Some minor adjustments like: Preferences > FDT > Build Path change Source folders to “source” (I like source above src) and Output folder to “deploy” (I like deploy above bin) Preferences > FDT > Code Style > Code Templates (Misc) to “Override System UserName –${user}

Preferences > FDT > Editor goto “Folding” and uncheck “Folding enabled” (I like to see everything, comment also)

Preferences > FDT > Tools > Flash/Flash Help to add paths to Flash (in my case: “H:\Program Files\Adobe\Adobe Flash CS4\Flash.exe”) and the Flash help files (in my case: “H:\Program Files\Adobe\Adobe Flash CS4\en\First Run\HelpPanel\Help”)

Preferences > General > Web Browser change to “Use external Web browser” to my favourite browser: Firefox (no Google Chrome there yet)
You can add any browser that you want.

Update #5: visit http://www.rumblingskies.com/blog/?p=75 and add FTP capabilities to ANT.

You have to create a code-template/code-snippet:
go to Preferences > FDT > Editor > Templates

This is a template that resembles the trace I used in FlashDevelop
Trace:

trace ( "+ ${enclosing_type}.${enclosing_method}() - args: " + [ ${enclosing_method_arguments} ] ); and I found some other useful templates Public method: public function${methodName}():${type} { trace(">>${enclosing_type}.${methodName}() args: "+[]);${cursor}
};

for some strange reason there is no shortcut for asdoc 🙁

ASDoc:

/**
* ${cursor} * @example * @param${enclosing_method_arguments}
* @return
*/
*/
Update #3: (sadly if there are no param in the function “${enclosing_method_arguments}” will be printed..) a switch a use a lot with FlashDevelop: Switch: switch (${value}) {
case ${result}: trace ("${result}" +${result} );${cursor}
break;
default:
trace("case '"+${value}+"':\r\ttrace ('--- "+${value}+"');\r\tbreak;" );
}


and the template for a singleton

Singleton: (from gskinner)

package ${enclosing_package} { /** * @author${user}
*/
public class ${enclosing_type} { private static var _instance:${enclosing_type};
private static var _allowInstantiation:Boolean;

public static function getInstance():${enclosing_type} { if (_instance == null) { _allowInstantiation = true; _instance = new${enclosing_type}();
_allowInstantiation = false;
}
return _instance;
}

public function ${enclosing_type}():void { if (!_allowInstantiation) { throw new Error("Error: Instantiation failed: Use${enclosing_type}.getInstance() instead of new.");
}
}

\${cursor}

} // end class

} // end package

enough for now, here some other posts about the subject

read here the complete (dutch) error message

Stupid, stupid, stupid, I already knew this: Flash cross-domain security.
Which simple says that it’s not allowed to “get” anything from another website unless the server has a crossdomain.xml.
The nasty part is that, while you are testing in Flash IDE nothing goes wrong. So I only bumped into this when I put it on my server…

So what to do?

1. Ask Twitter to change there crossdomain.xml and add my domain…… (is this really an option?)
2. Find something around the crossdomain security from Flash

Luckily solution two is the easiest one: use a proxy to get the data we want.
Because PHP doesn’t have the same restrictions as Flash has we will be using a proxy.php.

This is how it works: Flash wants a crossdomain.xml if you “get” data from another server, but if you “get” data from the same server there is no problem. So we will be asking the proxy.php to “get” the xml/rss and serve it to Flash.

http://twitter.com/statuses/user_timeline/27657030.rss
We will be using the proxy instead
http://yoursite.com/xml_proxy.php?url=http://twitter.com/statuses/user_timeline/27657030.rss

I didn’t write the proxy myself:
The proxy that I used can be found here: http://xmlrpcflash.mattism.com/proxy_info.php (it has some extra explanation about the subject )
This proxy can be use for all sorts of xml, and any server.

As always I’m reinventing the wheel: this group needed a specific solution but is nice to read more about it:
They wrote something similar, but a proxy more specific suited for twitter and the use of twitterscript.

Update #1: I found another proxy.php (I really don’t think you need another, but choices are nice 😀 ).
PHP Proxy Script for cross-domain requests
Sorry for the dutch error… I have a dutch version of XP (not my choice)
 Error #2044: Niet-afgehandelde securityError:. text=Error #2048: Schending van beveiligingssandbox: http://emceekay.nl/paper/flash/twttr.swf kan geen gegevens laden van http://twitter.com/statuses/user_timeline/27657030.rss. at nl.emceekay.twttr::TwttrBase/getFeed() at nl.emceekay.twttr::TwttrMain() 

Update #1: must read this post, otherwise this code will fail when you place it on your server!

I recently started my own company (eMCeeKay.nl) and I need to make a website for it…. Not really a problem besides that I don’t have any time to create a design.

So I was thinking about a easy way to update this website without spending extra time on that.

Because the main focus of the company is papertoys (urban papertoys), I need design or papertoy related info in my my new website ().

And I came with two ways to update it without extra effort: twitter (I tweet about a lot of stuff but primarily about papertoys) and this the content on this blog (category: urban-papercraft).

I started with the Twitter part.
But after reading the source I concluded that it was a little bit to much: I don’t want to tweet from emceekay.nl or do searches, so that was not the way to go.

The code on theflashlogs.org is pritty simple, and very easy to use.
So my code is a little addition to that, I need some stuff done to the rss feed:

• remove “MatthijsKamstra:” form the title
• convert @paperkraft to a link
• convert #Mecha6 to a link
• convert http:// to a link

Here is my code:
[as light=”false” wraplines=”false”]
package nl.emceekay.twttr
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.TextField;
/**
* // nl.emceekay.twttr.TwttrExample
* …
* @author Matthijs Kamstra aka [mck]
*/
public class TwttrExample extends MovieClip
{

private var _txt:TextField;

public function TwttrExample()
{
stage.scaleMode = "noScale";
stage.align = "TL";

// generate textfield
_txt = new TextField()
_txt.x = 10;
_txt.y = 10;
_txt.width = stage.stageWidth – 20;
_txt.height = stage.stageHeight – 20;
_txt.wordWrap = true;
_txt.multiline = true;
_txt.autoSize = "left";

// start
getFeed(url);
}

private function getFeed (inURL:String) : void
{
_txt.htmlText = "getting tweets";

}

private function onFeedHandler (e:Event):void
{
_txt.htmlText = "";
var _feed:XML = new XML(e.target.data);
var _item:XMLList = _feed.channel.item;
for each (var feedItem:XML in _item){
var _title :String = feedItem.title;
var _pubDate :String = feedItem.pubDate;

_title = convertTweet(_title);

_txt.htmlText += _title + "<br><i>" + _pubDate + "</i><br><br>";
}
}

// one place to convert the tweet
private function convertTweet (inString:String):String
{
var _str:String = inString;
_str = twttrStripName(_str);
_str = twttrConvertHTTP(_str);
_str = twttrConvertMention(_str);
_str = twttrConvertHashtag(_str);
_str = twttrConvertSmileys(_str);
return _str;
}

// remove the writers name from the tweet
private function twttrStripName (inString:String):String
{
var _str:String = inString;
var _charNumber:Number = _str.indexOf(":");
return _str.substr(_charNumber + 2);
}

private function twttrConvertHTTP(inString:String):String
{
var _str:String = inString;
var _array:Array = _str.split(" ");
for (var i:int = 0; i < _array.length; i++)
{
var _str2:String = twttrStripChar(_array[i]);
if (_array[i].indexOf("http") != -1)
{
_array[i] = "<u><a href=’" + _str2 + "’ target=’_blank’>" +_array[i] + "</a></u>";
}
}
return _array.join(" ");
}

// convert mentions (@) to links
private function twttrConvertMention(inString:String):String
{
var _str:String = inString;
var _array:Array = _str.split(" ");
for (var i:int = 0; i < _array.length; i++)
{
var _str2:String = twttrStripChar(_array[i]);
if (_array[i].substr(0, 1) == "@")
{
_array[i] = "<u><a href=’http://www.twitter.com/" + _str2.split("@")[1] + "’ target=’_blank’>" +_array[i] + "</a></u>";
}
}
return _array.join(" ");
}

// convert hashtags (#) to links
private function twttrConvertHashtag(inString:String):String
{
var _str:String = inString;
var _array:Array = _str.split(" ");
for (var i:int = 0; i < _array.length; i++)
{
var _str2:String = twttrStripChar(_array[i]);
if (_array[i].substr(0, 1) == "#")
{
_array[i] = "<u><a href=’http://twitter.com/search?q=%23" + _str2.split("#")[1] + "’ target=’_blank’>" +_array[i] + "</a></u>";
}
}
return _array.join(" ");
}

// TODO: [mck] convert 🙂 to a smiley image
private function twttrConvertSmileys(inString:String):String
{
var _str:String = inString;
return _str;
}

// remove "strange" characters from the end of the string
private function twttrStripChar(inString:String):String
{
var _str:String = inString;
var _charArray:Array = [‘,’, ‘;’, ‘:’, ‘ ‘, ‘-‘, ‘_’];
for (var i:int = 0; i < _charArray.length; i++)
{
if (_str.charAt(_str.length – 1) == _charArray[i]) {
_str = _str.substr(0, _str.length – 1);
}
}
return _str;
}

} // end class

} // end package
[/as]

Currently I have only this proof of concept, but soon I will post the example on emceekay.nl

Because this is part one of what I want to do, and don’t want to search for every link again, I’m posting also the WordPress link here (it’s just because I’m lazy).

So here the feeds I will be using:

# What a Flash / ActionScript Developer needs to know

Yesterday I saw this post in my RSS feeds, and I just want to remember this (and make sure that I’m really a senior 😉 )

So here is a list of stuff you need to know when you say you are a senior Flash/ActionScript developer:
http://pv3d.org/2009/08/28/10-things-every-senior-flash-developer-should-know/

I don’t like to regurgitate so I only show you the top 10, for examples visit the list by John Lindquist

1. The Elastic Racetrack
2. FlexSDK, mxmlc, compc, and all that jazz
3. Player Events, Custom Events, Event Bubbling
4. Statements, Keywords, and Directives
5. ASDoc
6. Managing visual assets (images, fonts, CSS, etc)
7. Arrays, Collections, Dictionaries, Mapping
8. Programmatic motion (tweening, easing)
9. OOP and Coding Against Frameworks
10. Version control