Actions

Through its powerful ActionScript language, Flash provides a flexible scripting environment to allow developers to take more direct control over the operation and flow of their script. For example, you can call stop() to stop playing the movie, then play() to continue; gotoFrame() allows you to jump to a particular part of your movie, and getURL() allows you to browse to a new web page. There is a large collection of actions available to you, and the PHP documentation has some very good (if long) examples on how to make use of various functions.

This next script gives you a quick start in using ActionScript:

    function MakeActionBox($red, $green, $blue){
            $shape = new SWFShape();
            $shape->setLeftFill($shape->addFill($red, $green, $blue));
            $shape->movePenTo(-100,-20);
            $shape->drawLineTo(100,-20);
            $shape->drawLineTo(100,20);
            $shape->drawLineTo(-100,20);
            $shape->drawLineTo(-100,-20);
            return $shape;
    }

    $button = new SWFButton();
    $button->setUp(MakeActionBox(0xff, 0, 0));
    $button->setOver(MakeActionBox(0xff, 0xff, 0));
    $button->setDown(MakeActionBox(0, 0, 0xff));
    $button->setHit(MakeActionBox(0, 0, 0));
    $button->addAction(new SWFAction("getURL('http://www.slashdot.org',
            'slashdot');"), SWFBUTTON_MOUSEUP);

    $movie = new SWFMovie();
    $movie->setDimension(200,200);

    $displayitem = $movie->add($button);
    $displayitem->moveTo(100,100);

    header("Content-type: application/x-shockwave-flash");
    $movie->output();

That script uses a custom function, MakeActionBox(), to handle some of the grunt work ...

Get PHP in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.