OOPS! advanced AS3 tracing

3 0 7th 2010 § 0 comments

This is something I am working on, not quite finished, but it is coming along nicely.
Basically the issue is that you can’t always trust that you will be viewing your precious SWF on a computer that has one of the awesome trace programs installed [ example ]. So I have my oops.as! It is an old class that I am rebuilding. The original had error checking built in, and I might eventually put dynamic error reporting in this one down the line, but I wanted to show the basic idea. You can see a live example here [ testTube ].

Code is called like this:

// ---- OOPS (traces out to text box)
import com.drpunchlogic.oops;

// OOPS
public var _oops:oops; // TRACE CLASS
public var _say:Function;

// add to stage
_oops = new oops();
_oops.x = 260;
_oops.y = 260;
addChild( _oops );
_say = _oops.say;
_say( "\t[ OOPS! ]" );

Code after the jump

package com.drpunchlogic
{
/*
-------------------------------------------------
	INCLUDE STUFF
-------------------------------------------------
*/
	// display objects
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.Graphics;

	// standard events
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.ProgressEvent;
	import flash.events.EventDispatcher;
	import flash.events.KeyboardEvent;

	// error checking
	import flash.events.ErrorEvent;
	import flash.events.IOErrorEvent;
	import flash.errors.IOError;
	import flash.errors.MemoryError;

	// text field stuff
    import flash.text.TextField;
    import flash.text.TextFieldType;
	import flash.text.TextFormat;
    import flash.text.TextFieldAutoSize;
    import flash.text.AntiAliasType;
	import flash.text.StyleSheet;

	// TweenMax
	import com.greensock.*;
	import com.greensock.easing.*;

	public class oops extends MovieClip
	{
// START --------------------------

/*
-------------------------------------------------
	SHARED VARIABLES
-------------------------------------------------
*/
		private var _str:String;
		private var _log:String = ''; 

		public var 	_oops:MovieClip; // the container
		private var _tf:TextField;
		private var _msk:Sprite; // masks the text field for the scroll
		private var _ps:punchSlider;

/*
-------------------------------------------------
	OOPS!
-------------------------------------------------
*/
		public function oops( ) : void
		{
			trace( "[ OOPS! ]" );
			addTF( 4, 330, 360, 260 );

			// alert that keys are pressed
			// addEventListener( KeyboardEvent.KEY_DOWN, keyHandler );
		}
/*
-------------------------------------------------
	oops.say
-------------------------------------------------
*/
		public function say( str:String , num:Number = 0 ) : void
		{
			trace( num, "\t" ,str );

			switch( num )
			{
				// error
				case( 1 ):
					_log += '<font color="#CC0000">' + str + '</font>\n';
					break;
				// info
				case( 2 ):
					_log += '<font color="#006600">' + str + '</font>\n';
					break;
				// url
				case( 3 ):
					_log += '<font color="#0066CC">' + str + '</font>\n';
					break;
				// event
				case( 4 ):
					_log += '<font color="#8000FF">' + str + '</font>\n';
					break;
				// not error
				default:
					_log += str + '\n';
					break;
			}

			_tf.htmlText = _log;

			if( _tf.height > _msk.height ) punchMod();

			// check depth
			//oopsDepth();
		}
/*
-------------------------------------------------
	CREATE TEXTFIELD
-------------------------------------------------
*/
		private function addTF( _x:Number, _y:Number, _w:Number, _h:Number ) : void
		{
           trace( "[ OOPS: addTF ]" );

		   // add the container
			_oops = new MovieClip();
			_oops.name = "OOPS";

			_oops.x = _x;
			_oops.y = _y;

			// format the text
			var styleObj:Object = new Object();
			var newStyle:StyleSheet = new StyleSheet();

            styleObj.fontWeight = "bold";
            styleObj.color = "#666666";
            newStyle.setStyle(".defStyle", styleObj);

			// add the textfield
			_tf = new TextField();
			_tf.name = "tf";

			_tf.multiline = true;
			_tf.selectable = false;

			_tf.width = _w;
			_tf.height = _h + 20;
			_tf.autoSize = TextFieldAutoSize.LEFT;

			//_tf.background = true;
			//_tf.backgroundColor = 0xdbdbdb;
			_tf.styleSheet = newStyle;

			_tf.htmlText = clrTXT();

			// add the mask
			_msk = new MovieClip();
			_msk.name = "tf_msk";

			_msk.graphics.lineStyle( 1, 0xff0000, 0.5, true );
			_msk.graphics.beginFill(0xff0000, 0.3);
			_msk.graphics.moveTo( 0,0 );
			_msk.graphics.lineTo( 0, _h );
			_msk.graphics.lineTo( _w, _h );
			_msk.graphics.lineTo( _w, 0 );
			_msk.graphics.lineTo( 0, 0 );

			// mask out the textfield
			_tf.mask = _msk;

			// add vert slider
			_ps = new punchSlider();
			_ps.x = _w + 20;
			_ps.y = 0;

			punchMod();

			// add to stage
			addChild(_oops);
			_oops.addChild(_tf);
			_oops.addChild(_msk);
			_oops.addChild(_ps);

			// hide until you are ready
			//showhideTXT();

			trace( "[ OOPS: added ]" );
        }
// Modify PunchSlider
		public function punchMod() : void
		{
			/*
				as the text box grows,
				we will need to modify
				the slider to fit
			*/
			_ps.init( _oops, _msk, _tf, true );
			_ps.visible = true;
		}

/*
-------------------------------------------------
	SHOW/HIDE TEXT
-------------------------------------------------
*/
		private function showhideTXT() : void
		{
			//( _oops.visible ) ? _oops.visible = false : _oops.visible = true;
			( _oops.x == 4 ) ? TweenLite.to(_oops, 1, {x:404}) : TweenLite.to(_oops, 1, {x:4});
		}
/*
-------------------------------------------------
	CLEAR TEXT
-------------------------------------------------
*/
		public function clrTXT() : String
		{
			//_log = helpTXT();
			_log = '';
			var txt:String = _log ; // clears the log and sets default
			return txt;
		}
/*
-------------------------------------------------
	HELP
-------------------------------------------------
*/
		private function helpTXT() : String
		{
			var txt:String;

			txt = '"<font color="#FF3300">[</font>" <font color="#666666">clear</font>';
			txt += ' \t ';
			txt += '"<font color="#FF3300">]</font>" <font color="#666666">show/hide</font>';
			txt += '\n';

			return txt;
		}
/*
-------------------------------------------------
	KEY PRESSED
-------------------------------------------------
*/
	private function keyHandler( e:KeyboardEvent ):void
	{
		var key:Number = e.keyCode;

		trace("[ " + key + " ]");

		switch( key )
		{
			case( 219 ):
				say( clrTXT() );
				break;
			case( 221 ):
				showhideTXT();
				break;
		}
	}
/*
-------------------------------------------------
	SWAPDEPTHS
-------------------------------------------------
*/
		public function oopsDepth( A:Number, B:Number ) : void
		{
			//var A:Number = _oops.parent.getChildIndex( this._oops );
			//var B:Number = _oops.parent.numChildren -1;

			if( A < B ) swapChildrenAt( A,B );
		}
// FINISHED ----------------------------
	}
}

Tagged , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

What's this?

You are currently reading OOPS! advanced AS3 tracing at DrPunchBlog.

meta

  •  

    March 2010
    M T W T F S S
    « Feb   Apr »
    1234567
    891011121314
    15161718192021
    22232425262728
    293031  
  • Archives

  • The Uber-Mannerist ...
    By Van Arno
  • RSS mtr.me

    • ‘Up In The Air’ Producer Launches The Allegiance Shingle With IM Global-Funded ‘Money Monster’
      EXCLUSIVE: Daniel Dubiecki has launched The Allegiance Theater, a association designed to emanate a breakwater where talent and financiers can induce film and TV projects. The association gets off a belligerent with a privately-backed beyond and growth account to beget character-driven, commercially appealing stories, pronounced Dubiecki. As Jason Reitman’s […]
    • New Oils
      James and Esao both published oil paintings to their blogs recently, James’s work on tip is titled, “Pauline Prieto“, and Esao’s investigate underneath it is substantially eleven or thirteen years aged now from art propagandize and he writes about because it is called “Grumpy Study”. Article source: http://meathaus.com/2012/02/06/new-oils/ […]
    • Video Game Character Facebook Profiles
      This is a array of cinema from a Facebook profiles of video diversion characters. Obviously they’re fake, that we wish we would’ve famous before spending a half hour perplexing to find and crony Nathan Drake and Solid Snake. OMG, how cold would it be to know those dual guys in genuine life? “Wow,GW — man-crush […]
  • Translator