String Permutations (From Java to AS2)

In order to learn AS2 i’ve started to study java more intensely and translate various code snippets to AS2 and to great suprise, some of them can be just copy/pasted (syntactically speaking). Here’s an example. I came across this link with some usefull java code to learn from. If you take a look at this PermuteString java class and the AS2 version below, you can see that i merely copied the code meat into an AS2 class (yeah, shame on me!).

class StringPermutator { private var word:String; private var index:Number; private var __substring:StringPermutator;

function StringPermutator(s:String) { word = s; index = 0; if(s.length > 1) __substring = new StringPermutator(s.substring(1)); }

public function hasMorePermutations():Boolean { return __index

and you can test it here.

Almost Died…

Yesterday (31st october) was a strange day. I could not boot my machine and it looked like one of my hds just died! This would mean all my important stuff (work files, mails and other things) would be gone for good…. of course, my last backup was from.. ehm… last year? :( Anyway, i was scared like shit.. and frustrated.. and pissed off.. and… and… There was no point in staring at the “failed to boot. please insert the system disk and press enter” message all day, so i switched the machine off and went doing other things (like hanging around with my dog and cats and other social stuff - seeing people!) ….

I woke up this morning, determined to fix the problem ( taking the corruped HD out and making a new, clean install of the OS - i already said goodbye to my files) …. i just wanted to try to boot it for the last time, although i already knew it would be in vain …… GUESS WHAT??? it booted alright! everything is like.. ok! i mean.. what happened yesterday? did one of the hard drives decide to dress up like a ghost and play invisible for the halloween?

oh, well… im doing my backups today :)

Extending AS2 Array

According to gSkinner’s post, when you extend an array you must call the superClass constructor in a particular way so that the indefinite amount of arguments get passed along correctly to the parent class: class ArrayExtended extends Array {

function ArrayExtended(){
    super.constructor.apply(this, arguments);
}
public function someFunc(){
      return length;
}

} Well, that never worked for me… actually that’s very strange because it appears as if it works for some but not for others..

today i came across a post a Tween Pix and the solution that i saw there is working: class ArrayExtended extends Array {

function ArrayExtended(){
    splice.apply(this, [0, 0].concat(arguments));
}
public function someFunc(){
      return length;
}

}

but im still wondering WHY the gskinner’s variant doesn’t work for me??!

UPDATE: The solution above (the one that works for me) was actually first posted at flashcoders mailing list

Central - First Try

Today i’ve been playing with macromedia central sdk. There is quite some new stuff to learn but it’s quite easy to make some simple “begginer” applications :) well.. here’s mine: GoogService

Its a fullasagoog blog readed and it uses flash remoting to connect to goog’s webservice. It’s still in its early stage and it’s not really good looking, but it gets the job done for now :) anyway.. now i have to learn how to save downloaded blogs for off line reading!

Many thanks to centralmx for posting it at their site! :)

New UI Components for FlashMX2004

Joey Lott, the author of Actionscript Cookbook, has posted a set of UI Flash Components at his site: - Button - Loader - ProgressBar - ScrollBar - ScrollPane - Window - TextArea

The reason, he writes, for making them is because the current MM components are rather heavy.. and some of them do not work properly. Lott’s components are still in the alpha stage, but if you want to try them you can download them here: www.person13.com/components

Webservices Are Easy

Just out of curiosity i tried the webserviceConnector component. I really wanted to see if it really is that simple to set up and use (as everybody is saying)… And, honestly, it took me 15 minutes to make it (5 minutes were spent on deciding which webservice i’m going to use). Knowing that WebserviceX.Net have recently put a crossdomain policy file up on their server, i tried my luck with their leingth/distance converter: http://www.webservicex.net/length.asmx?WSDL

Preview the service here

All you have to do is to open web service window (Window/developer Panels/Web Services), click on Define web service icon (that thing that looks like Earth) and type the url of the service in the pop up window. After a while (when flash connects to the service and recieves back the response) all the methods aviable from this service will be listed in that window. Now its’ only a matter of selecting which one you want to use, right click on it and select “Add method call” and flash will automatically place an instance of WebserviceConnector component on the stage. I also added a couple of comboboxes (for the unit names), a textInput , a textArea (which will display a result from the conversion) and a button on the stage. The trickiest part now is to bind the webserviceConnector to other components on stage. Ok, it sounds tricky, but it really is not ;) Select the webserviceConnector and click on the bindings tab in the Component Inspector panel and add your bindings (click on the +)… I added the simplest one first, the result that the service will send me. I selected it (the last one, called results:Number) and then set the “bound to” to point to my textArea component (more preciselly, its text property). I did the same with other parameters: params.LengthValue - bounded to textInput field:text params.fromLengthUnit - bounded to fromLengthUnit_combobox:value params.toLengthUnit - bounded to toLengthUnit_combobox:value

now, what’s left is just few lines of code: we want to trigger the service when we click on the button, so we have to write an event handler for that: goConvert = function (ev) { //ChangeLength_wbs is the instance name of the webservice component

ChangeLength_wbs.trigger();

};

convertButton_pb.addEventListener(“click”, goConvert);

Attached is a zipped fla for taking a closer look :)

Download zipped file

UPDATE: Just noticed that Vera Fleischer has written a great in-depth post on how to use webserviceConnector :)