setRate(20.000000); $w = 220; $h = 120; $movie->setDimension($w, $h); $movie->setBackground(255, 255, 0); $movie->setRate(31); /////////////////////////////////////////////////////////////////////////// function drawSquare($x0, $y0, $x1, $y1, $linesize, $r, $g, $b, $a=200) { $square = new SWFShape(); $square->setLine($linesize, $r, $g, $b, $a); $square->movePenTo($x0, $y0); $square->drawLineTo($x1, $y0); $square->drawLineTo($x1, $y1); $square->drawLineTo($x0, $y1); $square->drawLineTo($x0, $y0); return $square; } function drawFilledSquareAlpha($x0, $y0, $x1, $y1, $linesize, $r, $g, $b, $a) { $square = new SWFShape(); $square->setLine($linesize, $r, $g, $b, $a); $square->setRightFill($r, $g, $b, $a); $square->movePenTo($x0, $y0); $square->drawLineTo($x1, $y0); $square->drawLineTo($x1, $y1); $square->drawLineTo($x0, $y1); $square->drawLineTo($x0, $y0); return $square; } /////////////////////////////////////////////////////////////////////////// // funciton to create a sprite with the moveable object /////////////////////////////////////////////////////////////////////////// function makeMover($x, $y, $x1, $y1, $stroke, $r, $g, $b){ $s = new SWFSprite(); $alf = rand(50, 200); if(rand(0, 2) < 1){ $sq = drawSquare($x, $y, $x1, $y1, $stroke, $r, $g, $b, $alf); } else { $sq = drawFilledSquareAlpha($x, $y, $x1, $y1, 0, $r, $g, $b, rand(50, 200)); } $square2 = $s->add($sq); $s->nextframe(); return $s; } /////////////////////////////////////////////////////////////////////////// // gotta have this /////////////////////////////////////////////////////////////////////////// $font = "../MING/Dynomite.fdb"; $f = new SWFFont($font); $t = new SWFTextField(SWFTEXTFIELD_HTML | SWFTEXTFIELD_NOSELECT); $t->setFont($f); $t->setColor(133, 133, 133); $t->setHeight(7); $t->addString("there doesn't need to be a point"); $text = $movie->add($t); $text->moveto($w/4, $h/2); ////////////////////////// //vars for the square initialization $width = 20; $height = 20; ////////////////////////// // draw a 100 squares, some moving in the z axis, some in the x y for($i=0;$i<100; $i++){ //choose random x, y start position and r,g,b colors $x = $y = rand(0, $height); $r = $g = $b = rand(0, 155); $var = "square_".$i."_"; //create the sprite $$var = makeMover(0, 0, $x, $y, .5, $r, $g, $b); //add it to the movie $the=$movie->add($$var); //set its name so you can access it from AS $the->setName($var); //put it somewhere on the stage so it doesnt start at 0,0 $the->moveto(rand(0, $w-$width), rand(0, $h-$height)); //make half the objs move z, half xy if($i%2 == 0){ //if its in the z, start it as hidden $the->scaleto(.01, .01); $onenters .= $var.".onEnterFrame = move_z;\n"; } else { $onenters .= $var.".onEnterFrame = move_xy;\n"; } }//end for /////// mx actionscript /////// // based on Random Movement in Flash MX by // http://www.kirupa.com/developer/mx/random_motionMX.htm $strAction = " function getdistance(x, y, x1, y1) { var run, rise; run = x1-x; rise = y1-y; return (_root.hyp(run, rise)); } function hyp(a, b) { return (Math.sqrt(a*a+b*b)); } //----------------------- // The in out part //----------------------- MovieClip.prototype.reset_z = function() { //specify the width and height of the movie width = ".($w-$width)."; height = ".($h-$height)."; //------------------- var dist, norm; this.xscale = this._xscale; this.yscale = this._yscale; this.speed = Math.random()*2+2; this.targx = Math.random()*width; this.targy = Math.random()*height; dist = _root.getdistance(this.xscale, this.yscale, this.targx, this.targy); norm = this.speed/dist; this.diffx = (this.targx-this.xscale)*norm; this.diffy = (this.targy-this.yscale)*norm; }; move_z = function() { //MovieClip.prototype.move = if(this._rotation % 180 == 0){ //keep it moving if distance is greater than speed if (_root.getdistance(this.xscale, this.yscale, this.targx, this.targy)>this.speed) { this.xscale += this.diffx; this.yscale += this.diffy; } else { //otherwise stop it for a second this.xscale = this.targx; this.yscale = this.targy; if (!this.t) { //init timer if there isnt one this.t = getTimer(); } if (getTimer()-this.t>1000) { //wait after it gets there for an interval, then reset this.reset_z(); //this._rotation+=15; this.t = 0; } } this._xscale = this.xscale; this._yscale = this.yscale; } }; //----------------------- // The left right part //----------------------- MovieClip.prototype.reset_xy = function() { //specify the width and height of the movie width = ".($w-$width)."; height = ".($h)."; //------------------- var dist, norm; if(this._rotation % 180 == 0){ this.x = this._x; this.y = this._y; this.speed = Math.random()*2+2; this.targx = Math.random()*width; this.targy = Math.random()*height; dist = _root.getdistance(this.x, this.y, this.targx, this.targy); norm = this.speed/dist; this.diffx = (this.targx-this.x)*norm; this.diffy = (this.targy-this.y)*norm; } else { this._rotation+=15; } }; move_xy = function() { //MovieClip.prototype.move = if(this._rotation % 180 == 0){ //keep it moving if distance is greater than speed if (_root.getdistance(this.x, this.y, this.targx, this.targy)>this.speed) { this.x += this.diffx; this.y += this.diffy; } else { //otherwise stop it for a second this.x = this.targx; this.y = this.targy; if (!this.t) { //init timer if there isnt one this.t = getTimer(); } if (getTimer()-this.t>1000) { //wait after it gets there for an interval, then reset this.reset_xy(); this._rotation+=15; this.t = 0; } } this._x = this.x; this._y = this.y; } else { this.reset_xy(); } }; ".$onenters; //add the actionscript, save the movie. $movie->add(new SWFAction(str_replace("\r", "", $strAction))); $movie->save("inout.swf"); ?>