00:00
00:00
Gimmick
Thanks for dropping by!
NOTE: My outbox is full, so I may not be able to reply to PMs directly - might PM a reply via my alt or through comments.

Student

Somewhere

Joined on 8/20/08

Level:
28
Exp Points:
8,428 / 8,700
Exp Rank:
4,355
Vote Power:
6.96 votes
Rank:
General
Global Rank:
386
Blams:
1,969
Saves:
23,283
B/P Bonus:
48%
Whistle:
Silver
Medals:
2,487

Flash and Godot 4 event mappings

Posted by Gimmick - August 3rd, 2022


I'm learning Godot 4! Or at least, as much as I can given all the other stuff on my plate, haha.


I'm definitely going about it in a very roundabout way that I don't really recommend for others, given that I've always learnt this way and others may find it better to learn in a systematic manner. So I'm getting started with Godot scripting and coming from an AS2/3 background, I'm finding a lot of similarities between Godot's event system and Flash's event system. It's not surprising since both use a tree-like structure (Flash uses the Display List, whereas Godot uses Nodes, but both are effectively the same as the Document Object Model).


This newspost is an attempt to document the equivalent events / methods when moving from Flash to Godot. It's highly likely that I'll be proven wrong about my initial assumptions as I use the engine more, which is why this isn't a thread in the Game Development Forum yet.


Each bullet point in the sections below shows the event as it is named in Flash (AS3), with the AS2 equivalent (if available) and the Godot equivalent following it. All Godot examples use GDScript.



Constructor

public function ClassName() {
    //init
}

AS2:

onClipEvent(load) {
    //init
}

Godot:

func _init():
    pass

Event.ENTER_FRAME

import flash.events.Event;
function run_every_frame(evt:Event):void {
    //run
}
sprite.addEventListener(Event.ENTER_FRAME, run_every_frame)

AS2:

onClipEvent(enterFrame) {
    //run
}

Godot:

func _process(delta) -> void:
    pass

(There's also _physics_process(delta) which is independent of frame rate, but the direct equivalent is just _process since almost everything in Flash is dependent on the frame rate)


Event.ADDED

Triggered whenever a DisplayObject is added as a child of a DisplayObjectContainer, regardless of whether they are on a Stage or not.

import flash.events.Event;
function added_to_other_mc(evt:Event):void {
    //added to other mc
}
sprite.addEventListener(Event.ADDED, added_to_other_mc)

AS2: N/A

Godot: The direct equivalent appears to be "NOTIFICATION_PARENTED"

func _notification(id) -> void:
    match id:
        NOTIFICATION_PARENTED:
            pass

Event.REMOVED

The counterpart to Event.ADDED. Like ADDED, does not require the DisplayObjectContainer to be on a Stage or not. However, this is -for some reason- triggered before the object is removed, rather than after. This has historically lead to some hacks involving Timers or ENTER_FRAME events when running code after it is removed. A better name would have been "Event.REMOVING" as that could have also allowed it to be cancelable, but...oh well.

import flash.events.Event;
function removed_from_other_mc(evt:Event):void {
    //will be removed
}
sprite.addEventListener(Event.REMOVED, removed_from_other_mc)

AS2: N/A

Godot: It appears NOTIFICATION_UNPARENTED is the closest equivalent. I'm not sure whether this runs before or after the node is removed from its parent. Looking at the docs, it appears to be run after it is removed, but I haven't run it to verify.

func _notification(id) -> void:
    match id:
        NOTIFICATION_UNPARENTED:
            pass

Event.ADDED_TO_STAGE

Triggered when a DisplayObject is added to a Stage (yes, multiple Stages can exist in Adobe AIR, and this triggers whenever it is added to any of them)

import flash.events.Event;
function added_to_stage(evt:Event):void {
    //added to stage
}
sprite.addEventListener(Event.ADDED_TO_STAGE, added_to_stage)

AS2: I believe onClipEvent(load) does the same thing here, but the reference says onLoad runs whenever a MovieClip is added to the Stage (there's only 1 in AS2).

movieClip.onLoad = function() {
    //added to stage
}

Godot: Looks like _ready is the main equivalent here.

func _ready():
    # added to scene
    pass


I might add more as I work with Godot more. Depends on how much time I can afford to put into this right now.


First impressions: GDScript and Godot seem to be very clean and minimalistic in terms of verbosity. I think the design philosophy of Godot is that each Node has only 1 script and so an event system like Flash's doesn't make much sense in this context, but looking at the _notification function, it seems a bit clunky to have a sort of "master" function that gets an ID and then delegates it to other functions / branches. Of course, I'm biased towards how AS3 does it, but I think something like an

addListener(NOTIFICATION_ID, function)

might have been cleaner here. Looks like time will tell as I get used to GDScript.


Update: So it seems like Signals in GDScript are the equivalent of Listeners in AS3. However, I'm unsure as to why there's both signals and notifications. It sounds like it would be better to have just signals be used, with each Node subscribing to notifications the same way they would signals...but I'm not sure if or why that's not done.


Tags:

5

Comments

Why flash? Why not html 5? Heck JavaScript isn't even that hard to learn.

you’re learning godot

Yo, it's me again. Do I send you a PM for the raw fla? Last time we spoke, I think you mentioned something about having low PM space.

Yeah, you can send me a PM and I'll see it --- I can't send PMs as my outbox is full. I'll reply in the forum thread.

what do you think of Unity? i'm migrating there, mainly because i found an animation plug in that i'm betting will fit my needs just fine - once i get the hang of it

I haven't used Unity unfortunately, so I haven't got any opinion on it. You could give it a go if you found a plugin that fits your needs, and see if it works for you. You could try creating a thread in the Game Dev forum asking about Unity as there should be more people who use it there.

I want to start learning godot too Ill start on the weekend

im very excited to see what you make I feel like your coding skills are so good!

Aw shucks, thanks. But these days I mostly provide help/support on the forums for others in making games, because I find that making games takes too much time out of my limited schedule these days. Maybe in the future I might get back to making games seriously but most of the games I've published in the last 5 years or so have been one-day projects at best.

whoa... that's Gimmick!