Adding Shapes/Lines

Let's continue our journey into Ming by learning it's most important feature, the SWFShape(), and how it is used to create just about everything in your movie.

Keeping it to the basics, let's try drawing a line, then placing that line on our movie twice, once at the top and once at the bottom.

A) Begin as always by opening our html page and beginning our php code block:

<html>
<body>
<?php

B) Next, we must define our line as a SWFShape(). Defining our shapes first allows them to be used over and over without drawing them again and again.

$myShape1=new SWFShape();

C) Next, we set the line width and color for our shape.

$myShape1->setLine(5,0,0,255);

D) Next, we draw the line(s) for our shape.

$myShape1->drawLine(440,0);

E) Next, we create our SWFMovie as usuall and define it to our needs, in this case we are using the same definitions as Lesson1.

$myMovie=new SWFMovie();
$myMovie->setDimension(460,80);
$myMovie->setBackground(255,0,0);

F) Now, we can add our shape to the movie by creating an "instance" of it. You can create as many instances of a shape as you like once it has been defined. Just remember to give each instance a unique name in order to manipulate them later. Here, we add a line and place it near the top.

$firstLine=$myMovie->add($myShape1);
$firstLine->moveTo(10,10);

Here, we add another line and place it near the bottom.

$secondLine=$myMovie->add($myShape1);
$secondLine->moveTo(10,70);

G) Next, we save our movie, and close off our php code block as normal.

$myMovie->save("lesson2.swf");
?>

H) Finally, we add our swf file's html coding, and close our html document as normal.

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" ID=objects WIDTH=460 HEIGHT=80>
<PARAM NAME=movie VALUE="lesson2.swf">
<EMBED src="lesson2.swf" WIDTH=460 HEIGHT=80 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
</OBJECT>
</BODY>
</html>

Next lesson we will add more complex shapes and learn to fill them with colors.

Code summary for lesson 2:



Result: