Non-linear control flow added to AS3 through a new 'goto' keyword

178 views Asked by At

I recently read from adobe about the asc2.0 and air sdk 14 that there is a GOTO keyword you can use now, yet I cannot find anything other than that in the release notes online. Does anyone have an example of how to use goto?

1

There are 1 answers

0
BadFeelingAboutThis On

The most basic of examples:

goto myLabel;
trace("I'm going to get skipped");

myLabel:
trace("Here we are at the end");

If you run this, you will only get the ending trace.

goto in most languages (including AS3) will move code execution to the corresponding label.

AS3 has always supported labels, but previously you would use the break keyword to break out of a label.

myLabelOuter: {
    trace("First Outer");
    myLabelInner: {
        trace("First Inner");
        break myLabelOuter;
        trace("you'll never see this");
    }

    trace("You'll never see this either");
}

Here is a decent article I found with a simple web search that includes a bunch of examples: http://jacksondunstan.com/articles/2584

Keep in mind, the goto keyword only works in the Actionscript Compiler 2 (asc2), so it will not work in the current version of FlashPro (CC 2014), but only in FlashBuilder or other tools that use the newer compiler.