00:00
00:00
Gimmick
Thanks for dropping by!

Student

Somewhere

Joined on 8/20/08

Level:
28
Exp Points:
8,390 / 8,700
Exp Rank:
3,875
Vote Power:
6.96 votes
Rank:
General
Global Rank:
373
Blams:
1,969
Saves:
23,277
B/P Bonus:
48%
Whistle:
Silver
Medals:
2,487

Altering these settings may filter what you see.

Latest News

More

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.


4

Recent Game Medals

35,905 Points

Beat a Bot 5 Points

Won a game of single player

Beat a NGer 5 Points

Won a match against someone in online

Relevant 10 Points

Played on Madness Day (9/22)

Let's Rock and Roll! 5 Points

rock.

1 5 Points

Finish level 1

Cadet 5 Points

Finish the tutorial

Bugalopo 5 Points

Ancient Spirit of the Forest come to my aid.

KingofthePortal 5 Points

Bestowed only to the most creatives.

Brain In A Jar 5 Points

A collector's item.

Oh... 10 Points

Get the second power-up

Latest Shared Creations

Lamp

Added to pumpkins for Carve n' Share Jun 11, 2014.

My Pumpkin

Added to pumpkins for Carve n' Share Jun 11, 2014.

Hmm,

Added to pumpkins for Carve n' Share Feb 10, 2012.

Why

Added to pumpkins for Carve n' Share Feb 10, 2012.

Are

Added to pumpkins for Carve n' Share Feb 10, 2012.

You

Added to pumpkins for Carve n' Share Feb 10, 2012.