From AS2 to AS3 – Where did it go – onRelease

Last year I started working with AS3, and after having some startup problems, I’ve made my first application in it (not online yet).
The strange thing is, I started a new project and when I had to make a button from a movieclip, I immediately wrote it in AS2… 🙁

That AS2 is embedded deep into my brain and probably more people have this problem.
So I started this series of post about the stuff that’s changed in from AS2 to AS3.

I will probably regurgitate what other people already wrote something about, but it’s my “travel” trough AS3 land.

onRelease

One of things I use in every application that I build is onRelease.

This is what the ActionScript 2.0 Migration has to say about this:

ActionScript 2.0 ActionScript 3.0 Comments
onRelease() EventHandler flash.display.InteractiveObject dispatches event: mouseUp Replaced in the new event model by a mouseUp event.

In AS2 I know 3 ways to use it:

AS2

For this example you need a movieClip named ‘reload_mc‘ and this AS2 code placed in the root

example #1

// #1
this.reload_mc.onRelease = function (){
	trace ('onRelease AS2::reload button')
}

example #2

// #2
this.reload_mc.onRelease = reloadFunc;

function reloadFunc () {
	trace ('onRelease AS2::reload button')
}

example #3

// #3
var thisObj = this;
this.reload_mc.onRelease = function (){
	thisObj.reloadFunc ();
}
function reloadFunc () {
	trace ('onRelease AS2::reload button')
}

This a little different in AS3, but the good thing is I know of 2 ways to do this, but I only 1 can I explain.

AS3

For this example you need a movieClip named ‘reload_mc‘ and this AS2 code placed in the root
Explanation: in AS3 everything is done by Listeners, and so onRelease is replaced by MouseEvent.CLICK, and to compare the code below and AS2 examples above I would say that example #2 is the AS2 example that resembles AS3 code.
Example #3 is the one I always use but that code is more complex, so that will be another post.

example #1

import flash.events.MouseEvent;

reload_mc.buttonMode = true; // show hand icon when mouse is over the movie clip
reload_mc.addEventListener (MouseEvent.CLICK, reloadListener);

function reloadListener ($event:MouseEvent) {
	trace ('onRelease AS3::reload button')
}

Brendan Dawes created files that helped me a lot: as3 for lazy bastards like me.
I will probably write about the same subjects as he did in his files… But people who travel trough AS3 land will probably meet the same problems…

    5 thoughts on “From AS2 to AS3 – Where did it go – onRelease

    1. As many times as I’ve come across this I still seem to forget just enough to have to Google it again. I’ve seen this page twice in the past couple months so you’re a lifesaver multiple times over.

    2. I know the problem, but I’ve have some extra helpers now….
      One of them is my own blog, the other is from bit101 and the latest is a windows program called texter (just started using it yesterday, but seem promising)

    3. In AS2, there was onRelease and onPress. These were replaced with MouseEvent.MOUSE_UP and MouseEvent.MOUSE_DOWN, respectively.

      To make things more confusing, they added MouseEvent.CLICK which – from what I can tell – is called at the same time as MouseEvent.MOUSE_DOWN. The difference (I think?) is that it also appears to force a MouseEvent.MOUSE_UP event to fire immediately after.

    4. Pingback: Field5 secret design blog » Blog Archive » Wielki kambek!

    Comments are closed.