setRate(31); $movie->setDimension(550,400); $movie->setBackground(rand(0,0xFF),rand(0,0xFF),rand(0,0xFF)); // this creates a color cube sprite which sets _global.colorPickerRGB // when clicked. all the code is in the makeColorCubeSprite.php include include "makeColorCubeSprite.php"; $colorcubesprite=makeColorCubeSprite(); $f1=$movie->add($colorcubesprite); $f1->moveTo(18,18); $f1->setName("colorcube"); // some actionscript to enable drawing $strAction = join("", file("drawing.as"));; $movie->add(new SWFAction($strAction)); // save swf with same name as filename $swfname = basename(__FILE__,".php"); $movie->save("$swfname.swf",9); ?> /******************************************************************************** * @ File: drawing.as * @ Original date: January 2004 @ www16.brinkster.com/gazb/ming/ * @ Version: 1.2 * @ Summary: drawing code for colorpicker * @ Updated: small improvements and summary text * @ Copyright (c) 2003-2007, www.gazbming.com - all rights reserved. * @ Author: gazb.ming [[@]] gmail.com - www.gazbming.com * @ Released under GNU Lesser General Public License - http://www.gnu.org/licenses/lgpl.html ********************************************************************************/ createEmptyMovieClip('movieBG', -10); with(movieBG){ beginFill(0x000030, 100); moveTo(0, 0); lineTo(800, 0); lineTo(800, 800); lineTo(0, 800); lineTo(0, 0); endFill(); _x=-100; _y=-100; }; colorcube.swapDepths(60000); lineW=8; // make an object and attach actions drawingcontrols = { onMouseDown: function () { rx=_root._xmouse; ry=_root._ymouse; onMouseMove=this.doDrawing; oldx=_xmouse; oldy=_ymouse; }, onMouseUp: function () { onMouseMove=null; }, doDrawing: function () { rx=_root._xmouse; ry=_root._ymouse; line=base.createEmptyMovieClip('line'+ ++d, d); line.lineStyle(lineW, colorPickerRGB, 100); line.moveTo(oldx, oldy); line.lineTo(_xmouse, _ymouse); oldx=_xmouse; oldy=_ymouse; updateAfterEvent(); }, onKeyDown:function () { switch(Key.getCode()) { case 85: //Key.u: base['line'+ d].removeMovieClip();if(d>0){d--;}; break; case 32: //Key.SPACE: base.removeMovieClip();this.initclip(); break; case 187: //Key.+: lineW++; break; case 189: //Key.-: if(lineW>1){lineW--;}; break; case 49: //Key.1: lineW=1; break; case 50: //Key.2: lineW=2; break; case 51: //Key.3: lineW=3; break; case 52: //Key.4: lineW=4; break; case 53: //Key.5: lineW=5; break; case 54: //Key.6: lineW=6; break; case 55: //Key.7: lineW=7; break; case 56: //Key.8: lineW=8; break; case 57: //Key.9: lineW=9; break; case 48: //Key.0: lineW=0; break; } }, initclip:function () { d = 0; createEmptyMovieClip('base', 0); } }; drawingcontrols.initclip(); // add listeners to object Mouse.addListener(drawingcontrols); Key.addListener(drawingcontrols); > 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; $cube=new SWFShape(); $cube->setRightFill($r,$g,$b); $cube->setLine(1,0,0,0); $cube->drawLine(10,0); $cube->drawLine(0,10); $cube->drawLine(-10,0); $cube->drawLine(0,-10); $f1 = $colorcubesprite->add($cube); $f1->moveTo(($m*10),($n*10)); } } $colorcubesprite->nextFrame(); $colorcubespritewrapper= new SWFSprite(); $f2 = $colorcubespritewrapper->add($colorcubesprite); $f2->addAction(new SWFAction($colorcubeAction),SWFACTION_ONLOAD); $colorcubespritewrapper->nextFrame(); // make some more sprites, background, title bar, etc // define sprites $bgdef = array ( "w"=>210,"h"=>180, "bev"=>2, "r"=>224,"g"=>208, "b"=>152, "rl"=>0xf0,"gl"=>0xed, "bl"=>0xb0, "rd"=>0xc0,"gd"=>0xa0, "bd"=>0x38, "fill"=>1); $selectedcoledgedef = array ( "w"=>40,"h"=>20,"bev"=>2, "r"=>224,"g"=>208, "b"=>152, "rl"=>0xc0,"gl"=>0xa0, "bl"=>0x38, "rd"=>0xf0,"gd"=>0xed,"bd"=>0xb0, "fill"=>1); $selectedcolhexedgedef = array ( "w"=>80,"h"=>18,"bev"=>2, "r"=>255,"g"=>255, "b"=>255, "rl"=>0xc0,"gl"=>0xa0, "bl"=>0x38, "rd"=>0xf0,"gd"=>0xed,"bd"=>0xb0, "fill"=>1); $selectedcoldef = array ("w"=>40,"h"=>20,"r"=>0,"g"=>0,"b"=>0, "fill"=>1); // make sprites $selectedcol= makeCube($selectedcoldef); $bgsp= makeCube($bgdef); $selectedcoledge= makeCube($selectedcoledgedef); $selectedcolhexedge= makeCube($selectedcolhexedgedef); $titlebar=makeTitleBar(201,20,128,0,0); $selectedcolhex = maketextfield('selectedcolhex', '_sans','0x000000', 74, 18,0x33,0x33,0x33); // finally add all of the above to the holder sprite which will be added to the movie $holder= new SWFSprite(); $f1 = $holder->add($bgsp); $f1->moveTo(0,0); $f2 = $holder->add($colorcubespritewrapper); $f2->moveTo(4,55); $f3 = $holder->add($selectedcoledge); $f3->moveTo(6,30); $f3 = $holder->add($selectedcol); $f3->addAction(new SWFAction('this.useHandCursor=0;this.onPress=function(){bgcol=new Color(_root.movieBG);bgcol.setRGB(colorPickerRGB);};'),SWFACTION_ONLOAD); $f3->moveTo(6,30); $f3->setName('selectedcol'); $f4 = $holder->add($selectedcolhexedge); $f4->moveTo(122,30); $f5 = $holder->add($selectedcolhex); $f5->moveTo(126,31); $f6 = $holder->add($titlebar); $f6->moveTo(4, 5); $holder->nextFrame(); return $holder; }; // some helper functions // a function to draw cubes and bevels function makeCube($o){ $s=new SWFShape(); if($o["ln"]!=NULL){$s->setLine($o["ln"],0,0,0);}; if($o["fill"]!=NULL){$s->setRightFill($o["r"],$o["g"],$o["b"]);}; $s->drawLine($o["w"],0); $s->drawLine(0,$o["h"]); $s->drawLine(-$o["w"],0); $s->drawLine(0,-$o["h"]); if($o["bev"]==NULL){ $sp= new SWFSprite(); $f1 = $sp->add($s); $sp->nextFrame(); return $sp; } // top $s->setRightFill($o["rl"],$o["gl"],$o["bl"]); $s->drawLine(-$o["bev"],-$o["bev"]); $s->drawLine($o["w"]+(2*$o["bev"]),0); $s->drawLine(-$o["bev"],$o["bev"]); $s->drawLine(-$o["w"],0); // left $s->setRightFill($o["rl"],$o["gl"],$o["bl"]); $s->drawLine(0,$o["h"]); $s->drawLine(-$o["bev"],$o["bev"]); $s->drawLine(0,-$o["h"]-(2*$o["bev"])); $s->drawLine($o["bev"],$o["bev"]); $s->movePenTo(0, $o["h"]); //bottom $s->setRightFill($o["rd"],$o["gd"],$o["bd"]); $s->drawLine($o["w"],0); $s->drawLine($o["bev"],$o["bev"]); $s->drawLine(-$o["w"]-(2*$o["bev"]),0); $s->drawLine($o["bev"],-$o["bev"]); $s->movePenTo($o["w"],$o["h"]); // right $s->setRightFill($o["rd"],$o["gd"],$o["bd"]); $s->drawLine(0,-$o["h"]); $s->drawLine($o["bev"],-$o["bev"]); $s->drawLine(0,$o["h"]+(2*$o["bev"])); $s->drawLine(-$o["bev"],-$o["bev"]); $sp= new SWFSprite(); $f1 = $sp->add($s); $sp->nextFrame(); return $sp; }; // make a text field function function maketextfield($name,$font,$str,$w,$h,$r,$g,$b) { //$txtfield = new SWFTextField(SWFTEXTFIELD_DRAWBOX | SWFTEXTFIELD_MULTILINE | SWFTEXTFIELD_WORDWRAP | SWFTEXTFIELD_USEFONT ); $txtfield = new SWFTextField( SWFTEXTFIELD_USEFONT | SWFTEXTFIELD_NOSELECT ); $txtfield->setHeight(14); $txtfield->setBounds($w,$h); $txtfield->setName($name); $txtfield->setColor($r,$g,$b); $txtfield->setFont(new SWFFont($font)); $txtfield->addChars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); $txtfield->addString($str); return $txtfield; }; // just a function to draw the TitleBar function makeTitleBar($w,$h,$r,$g,$b){ $myshape=new SWFShape(); //$myshape->setLine(0,0,0,0); $myshape->setRightFill($r,$g,$b); $myshape->drawLine($w,0); $myshape->drawLine(0,$h); $myshape->drawLine(-$w,0); $myshape->drawLine(0,-$h); $titlebar = maketextfield('titlebartext', '_sans',' Color Picker', 88, 18,0xcc,0xcc,0xcc); $sp= new SWFSprite(); $f1 = $sp->add($myshape); $f2 = $sp->add($titlebar); $sp->nextFrame(); return $sp; }; ?>