Notes to Lesson 11
Below is an example of using a red button to rotate a blue square, obtained from
techrepublic.com
.
addFill(0, 0, 0xff); $square->setRightFill($sqfill); $square->movePenTo(-25,-25); $square->drawLineTo(25,-25); $square->drawLineTo(25,25); $square->drawLineTo(-25,25); $square->drawLineTo(-25,-25); //Now we can use that shape in a movie clip and define some actions: $sqclip = new SWFSprite(); $i = $sqclip->add($square); $i->setDepth(1); $sqclip->setframes(25); $sqclip->add(new SWFAction("stop();")); $sqclip->nextFrame(); $sqclip->add(new SWFAction("play();")); for($n=0; $n<24; $n++) { $i->rotate(-15); $sqclip->nextFrame(); } /* Next we'll create another shape and use it for a button. Rather than create a separate shape for each button action (over, down, up, and release), I've created a function to automate drawing the shapes: */ function rect($r, $g, $b) { $s = new SWFShape(); $s->setRightFill($s->addFill($r, $g, $b)); $s->drawLine(50,0); $s->drawLine(0,50); $s->drawLine(-50,0); $s->drawLine(0,-50); return $s; } $b = new SWFButton(); $b->addShape(rect(0xff, 0, 0), SWFBUTTON_UP | SWFBUTTON_HIT); $b->addShape(rect(0, 0xff, 0), SWFBUTTON_OVER); $b->addShape(rect(0, 0, 0xff), SWFBUTTON_DOWN); $b->addAction(new SWFAction("setTarget('/box'); gotoandplay(2);"), SWFBUTTON_MOUSEDOWN); /* Next, we define the movie and place the movie clip (sprite) and the button in the movie itself: */ $m = new SWFMovie(); $m->setDimension(400,300); $i = $m->add($sqclip); $i->setDepth(3); $i->moveTo(165, 40); $i->setName("box"); $i = $m->add($b); $i->setDepth(2); $i->moveTo(140,90); /* Finally, we send the output to the browser: */ header('Content-type: application/x-shockwave-flash'); $m->output(); $m->save("Note11.swf"); ?>
Result: