// ********************************************************************************** // Written by Nate Chatellier (nate@natejc.com) // Created on March 12, 2008 // Last Updated on March 14, 2008 // http://blog.natejc.com // // // LICENSE: Creative Commons Attribution 3.0 United States // http://creativecommons.org/licenses/by/3.0/us/ // // You are free: // * to Share — to copy, distribute, display, and perform the work // * to Remix — to make derivative works // // Under the following conditions: // * Attribution: licensees may copy, distribute, display and perform the work and make derivative works based on it only if they give the author or licensor the credits in the manner specified by these (but not in any way that suggests that they endorse you or your use of the work). // * For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page. // * Any of the above conditions can be waived if you get permission from the copyright holder. // * Apart from the remix rights granted under this license, nothing in this license impairs or restricts the author's moral rights. // // ********************************************************************************** // PURPOSE: // To help take a frame by frame Flash prototype and quickly acquire all of the x,y coordinates for any of the symbols // placed on the stage at design time. The top left x,y coordinates are displayed first, then the center x,y coordinates // in parenthesis. // USAGE: // - Copy and paste this code into frame 1 of any Flash file // - Make sure all objects that you want wireframes for are Symbols (for some reason, the x,y is off if they aren't) // - Run the swf // - Use the arrows keys to change frames // - Use space bar to toggle wireframe view // - You may press the space bar multiple times to get new random colors // - You can click and drag on the x,y text to move it to a new location // TODO: // - add a png exporter on ENTER or CTRL+S // CONFIGURABLES: var _nOriginalSpriteAlpha:Number = 0.2; var _nLineThickness:Number = 1.0; var _nTextBGAlpha:Number = 0.6; var _tfFormat:TextFormat = new TextFormat(); _tfFormat.font = "Arial Bold"; _tfFormat.size = 10; _tfFormat.align = "left"; _tfFormat.bold = true; // ********************************************************************************** var _bShowWireframes:Boolean = false; var _aWireframeTxts:Array = new Array(); var _mcWireframes:Sprite = new Sprite(); _mcWireframes.mouseEnabled = false; this.addChild(_mcWireframes); stop(); this.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown); // ********************************************************************************** function showWireframes(bShow:Boolean = true):void { _bShowWireframes = bShow; var i:uint; if (_bShowWireframes) { var mcCurrentChild:DisplayObject; var txtCurrentText:TextField; var nCurrentColor:uint = 0x000000; _tfFormat.color = nCurrentColor; for (i = 0; i < this.numChildren; i++) { mcCurrentChild = this.getChildAt(i); if (mcCurrentChild && i != this.getChildIndex(_mcWireframes) && mcCurrentChild.width > 0 && mcCurrentChild.height > 0) { _mcWireframes.graphics.lineStyle(_nLineThickness, nCurrentColor, 1.0); _mcWireframes.graphics.drawRect(mcCurrentChild.x, mcCurrentChild.y, mcCurrentChild.width, mcCurrentChild.height); mcCurrentChild.alpha = _nOriginalSpriteAlpha; txtCurrentText = new TextField(); txtCurrentText.text = roundDecPl(mcCurrentChild.x,1)+"x"+roundDecPl(mcCurrentChild.y,1)+" \n("+roundDecPl(mcCurrentChild.x+(mcCurrentChild.width*.5), 1)+"x"+roundDecPl(mcCurrentChild.y+(mcCurrentChild.height*.5), 1)+") "; txtCurrentText.width = txtCurrentText.textWidth; txtCurrentText.height = txtCurrentText.textHeight; txtCurrentText.selectable = false; txtCurrentText.mouseEnabled = false; _aWireframeTxts[i] = new Sprite(); Sprite(_aWireframeTxts[i]).addEventListener(MouseEvent.MOUSE_DOWN, startTxtDrag, false, 0, true); Sprite(_aWireframeTxts[i]).addEventListener(MouseEvent.MOUSE_UP, stopTxtDrag, false, 0, true); Sprite(_aWireframeTxts[i]).addChild(txtCurrentText); var nR:uint = (Math.random() * 170) << 16; var nG:uint = (Math.random() * 170) << 8; var nB:uint = (Math.random() * 170); var nRGB:uint = nR | nG | nB; Sprite(_aWireframeTxts[i]).graphics.beginFill(0xFFFFFF, _nTextBGAlpha); Sprite(_aWireframeTxts[i]).graphics.drawRect(0, 0, txtCurrentText.width, txtCurrentText.height) Sprite(_aWireframeTxts[i]).graphics.endFill(); Sprite(_aWireframeTxts[i]).x = mcCurrentChild.x; Sprite(_aWireframeTxts[i]).y = mcCurrentChild.y; Sprite(_aWireframeTxts[i]).mouseEnabled = true; Sprite(_aWireframeTxts[i]).useHandCursor = true; _tfFormat.color = nCurrentColor; txtCurrentText.setTextFormat(_tfFormat); nCurrentColor = nRGB; } // END IF } // END FOR for (i = 0; i < _aWireframeTxts.length; i++) { if (_aWireframeTxts[i]) this.addChild(_aWireframeTxts[i]); } // END FOR _mcWireframes.alpha = 1; } else { for (i = 0; i < _aWireframeTxts.length; i++) { if (_aWireframeTxts[i]) { this.removeChild(_aWireframeTxts[i]); _aWireframeTxts[i] = null; } // END IF } // END FOR for (i = 0; i < this.numChildren; i++) { mcCurrentChild = this.getChildAt(i); if (mcCurrentChild && mcCurrentChild != _mcWireframes) mcCurrentChild.alpha = 1; _mcWireframes.graphics.clear(); } // END FOR } // END IF } // END FUNCTION showWireframes // ********************************************************************************** function keyDown(e:KeyboardEvent):void { if (e.keyCode == Keyboard.LEFT) { showWireframes(false); if (this.currentFrame > 1) this.gotoAndStop(this.currentFrame - 1); else this.gotoAndStop(this.totalFrames); } else if (e.keyCode == Keyboard.RIGHT) { showWireframes(false); if (this.currentFrame < this.totalFrames) this.gotoAndStop(this.currentFrame + 1); else this.gotoAndStop(1); } else if (e.keyCode == Keyboard.SPACE) { showWireframes(!_bShowWireframes); } // END IF } // END FUNCTION keyDown // ********************************************************************************** function roundDecPl(nNum:Number, nDecPl:uint = 0):Number { var nMultiplier:uint = Math.pow(10, nDecPl); return Math.round(nNum * nMultiplier) / nMultiplier; } // END FUNCTION roundDecPl // ********************************************************************************** function startTxtDrag(e:MouseEvent):void { e.target.startDrag(); } // END FUNCTION startTxtDrag // ********************************************************************************** function stopTxtDrag(e:MouseEvent):void { e.target.stopDrag(); } // END FUNCTION stopTxtDrag // **********************************************************************************