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') }
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 replies on “From AS2 to AS3 – Where did it go – onRelease”
thanks for clear info on as3 š
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.
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)
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.
[…] Do nauki as3 postanowi?am przygotowywa? si? stopniowo, zak?adaj?c ?e b?d? po?wi?ca? dziennie godzink? na poznanie nowych zasad, i pr?dzej czy pó?niej w ko?cu pojm? ten j?zyk na tyle ?e b?d? mog?a przyst?pi? do pracy. W teorii za?o?enie pi?kne, w praktyce jak zwykle. Zawsze znajdzie si? co? lepszego, wa?niejszego, ciekawszego do roboty ni? po?wi?canie godzinki na czytanie kursów i tutoriali. I tak chc?c nie chc?c pó? roku pó?niej i przerobionych 3 lekcjach, dosz?am do wniosku ?e pora spróbowa? bardziej drastycznych metod samokszta?cenia. Skacz?c od razu na g??bok? wod? bez prawa wyboru otwar?am dokument flasha i ustawi?am na as3 i rozpocz??am prac? nad kolejnym zleceniem. Termin mnie goni wi?c trzeba robi? a nie spoczn? puki nie sko?cz?. A dla wszystkich, podobnych do mnie, actionscriptowych osio?ków stwarzam nowy topik pod tytu?em Migracja z as3 do as2, który to na swoim blogu zapocz?tkowa? pewien osobnik którego imienia nie znam ale pomys?y ma dobre »szczegó?y tutaj […]