#!/usr/bin/perl -w use strict; use SWF::Shape (); use SWF::Constants qw(:Button); my $max_x = 500; my $max_y = 200; print "Content-type: application/x-shockwave-flash\n\n"; my $line_sh = new SWF::Shape(); $line_sh->setLine(5,0,0,255); $line_sh->drawLine(100,100); # and use 'scale' to move line around my $line_mc = new SWF::MovieClip(); my $line_mci = $line_mc->add($line_sh); $line_mc->nextFrame(); sub rect($$$) { my ($r, $g, $b) = @_; my $s = new SWF::Shape(); $s->setRightFill($s->addFill($r, $g, $b, 0x00)); $s->drawLine($max_x,0); # 0,0 -> maxx,0 => dx,dy = maxx,0 $s->drawLine(0, $max_y); # maxx,0 -> maxx,maxy => dx,dy = 0,maxy $s->drawLine(-$max_x,0); # maxx,maxy -> 0,maxy => dx,dy = -maxx,0 $s->drawLine(0,-$max_y); # 0,maxy -> 0,0 => dx,dy = 0,-maxy return $s; } my $m = new SWF::Movie(); $m->setBackground(0xff, 0xff, 0xff); $m->setDimension($max_x,$max_y); $m->setRate(60.0); my $firstLine = $m->add($line_mc); $firstLine->moveTo(-$max_x,-$max_y); # hack $firstLine->setName('todLine'); $m->add( new SWF::Action(" function drawLine(xStart, yStart, xStop, yStop) { todLine.duplicateMovieClip('Line'+iDepth, iDepth); this['Line'+iDepth]._x = xStart; this['Line'+iDepth]._y = yStart; this['Line'+iDepth]._xscale = xStop-xStart; this['Line'+iDepth]._yscale = yStop-yStart; } function moveLines() { // delete existing lines for (i=(iDepth-nLines); i < iDepth; i++) { _root['Line'+i].removeMovieClip(); } // draw new lines with new midpoint for (i=0; i < nLines; i++) { xMid = _root._xmouse; yMid = _root._ymouse; drawLine(xStart[i], _root.yStart[i], xMid, yMid); iDepth++; } } iDepth = 0; nLines = 50; xStart = new Array(nLines); yStart = new Array(nLines); xMid = $max_x/2; yMid = $max_y/2; for (i=0; i < nlines; i++) { xStart[i] = Math.random()*$max_x; yStart[i] = Math.random()*$max_y; drawLine(xStart[i], yStart[i], xMid, yMid); iDepth++; } stop(); ")); my $b = new SWF::Button(); $b->addShape( rect(0,0,0), SWFBUTTON_UP | SWFBUTTON_HIT | SWFBUTTON_OVER | SWFBUTTON_DOWN); $b->addAction( new SWF::Action("moveLines(); stop();"), SWFBUTTON_MOUSEUP ); $b->addAction( new SWF::Action("gotoFrame(1); play();"), SWFBUTTON_MOUSEDOWN ); $m->add($b); $m->nextFrame(); $m->add( new SWF::Action("moveLines();") ); $m->nextFrame(); $m->add( new SWF::Action("prevFrame(); play();") ); $m->nextFrame(); $m->output();