1  /**
     2   * com.sekati.display.BaseClip
     3   * @version 1.1.5
     4   * @author jason m horwitz | sekati.com
     5   * Copyright (C) 2007  jason m horwitz, Sekat LLC. All Rights Reserved.
     6   * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
     7   */
     8  
     9  import com.sekati.display.IBaseClip;
    10  import com.sekati.display.ITweenClip;
    11  import com.sekati.core.KeyFactory;
    12  import com.sekati.except.IllegalArgumentException;
    13  import com.sekati.reflect.Stringifier;
    14  import com.sekati.utils.MovieClipUtils;
    15  import com.sekati.validate.TypeValidation;
    16  import caurina.transitions.Tweener;
    17  
    18  /**
    19   * This is the foundational MovieClip class and should be
    20   * thought of as the main building block of the SASAPI framework.
    21   * @see {@link com.sekati.display.CoreClip}
    22   */
    23  class com.sekati.display.BaseClip extends MovieClip implements IBaseClip, ITweenClip {
    24  
    25  	private var _this:MovieClip;
    26  	private var __isClean:Boolean;
    27  
    28  	public function BaseClip() {
    29  		_this = this;
    30  		__isClean = false;
    31  		KeyFactory.inject( _this );
    32  	}
    33  
    34  	/**
    35  	 * if destroy hasnt already been called manually
    36  	 * run it onUnload.
    37  	 */
    38  	public function onUnload():Void {
    39  		if(!__isClean) {
    40  			destroy( );
    41  		}	
    42  	}
    43  
    44  	/**
    45  	 * Destroy object elements and events for proper garbage collection.
    46  	 * This is a generic destroy method to insure that, at a minimum, the 
    47  	 * enterFrame and clip itself are removed when destroy is called. 
    48  	 * This behavior can be overwritten by BaseClip's subclasses. 
    49  	 * If you wish to use BaseClip's destroy in addition to your subclass 
    50  	 * destroy you may do so via: 
    51  	 * {@code
    52  	 * 	super.destroy(); 
    53  	 * }
    54  	 */	
    55  	public function destroy():Void {
    56  		__isClean = true;
    57  		_this.onEnterFrame = null;
    58  		/*
    59  		 * VERY DANGEROUS BUGS CAN OCCUR WHEN EXTENDING 
    60  		 * BASECLIP WITH THIS LOOP INCLUDED!
    61  		for(var i in _this) {
    62  		MovieClipUtils.rmClip(_this[i]);	
    63  		}
    64  		 */
    65  		MovieClipUtils.rmClip( _this );		
    66  	}
    67  
    68  	/**
    69  	 * Built-in {@link com.sekati.transitions.Tweener.addTween} wrapper. The method 
    70  	 * accepts either one argument (TweenerObject) or two arguments (target, TweenerObject).
    71  	 * {@code Usage:
    72  	 * 	tween({_x:100, time:1, transition:"linear"});
    73  	 * 	tween(someOtherMc, {_x:100, time:1, transition:"linear"});
    74  	 * }
    75  	 * @see {@link http://hosted.zeh.com.br/tweener/docs/en-us/}
    76  	 * @return Void
    77  	 */
    78  	public function tween():Void {
    79  		if (arguments.length == 1) {
    80  			Tweener.addTween( _this, arguments[0] );
    81  		} else if (TypeValidation.isMovieClip( arguments[0] ) || TypeValidation.isTextField( arguments[0] )) {
    82  			Tweener.addTween( arguments[0], arguments[1] );	
    83  		} else {
    84  			throw new IllegalArgumentException( this, "BaseClip.tween requires either (tweenerObject) or (target, tweenerObject) arguments.", arguments );
    85  		}
    86  	}
    87  
    88  	/**
    89  	 * Remove any or all Tweener tweens on the instance object using arguments array.
    90  	 * @param arguments
    91  	 * @return Void
    92  	 */
    93  	public function stopTween():Void {
    94  		var args:Array = [ _this ];
    95  		for (var i:Number = 0; i < arguments.length ; i++) {
    96  			args.push( arguments[i] );
    97  		}
    98  		Tweener.removeTweens.apply( this, args );
    99  	}
   100  
   101  	/**
   102  	 * return reflective output
   103  	 * @return String
   104  	 */	
   105  	public function toString():String {
   106  		return Stringifier.stringify( this );
   107  	}
   108  }