Home Tutorials Forums Articles Blogs Movies Library Employment Press
Home » Actionscripts library »  Object Object

Next 5

BitmapData creator

/*-----
Author: Tim Henager
Usage:
1. use createFromLibrary() to create a bitmapData object of an embedded image:
var bitmap:BitmapData = createFromLibrary("imageID"); //imageID = linkageID of image to create as bitmapData object

2. Use createFromExternal() to create a bitmapData object of an externally loaded image:
var bitmap:BitmapData;

loadListener.onLoadInit = function(loader_mc:MovieClip) {
//-----this function call is optional-----//
bitmapOptions(matrix, colorTransform, blendMode, smoothing);
//-----returns the bitmapData Object-----//
bitmap = createFromExternal(loader_mc);
};
----*/

import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.geom.ColorTransform;
import flash.geom.Rectangle;

class com.bitmap.CreateBitmapData extends MovieClip
{
        
        public var options:Boolean;
        public var b_matrix:Matrix;
        public var b_color:ColorTransform;
        public var b_blend:String;
        public var b_smooth:Boolean;
        
        public function CreateBitmapData(){}
        
        //-----Set bitmapData.draw parameters (optional)-----//
        public function bitmapOptions(matrix:Matrix, tint:ColorTransform, blend:String, smooth:Boolean):Void
        {
                b_matrix = matrix;
                b_color = tint;
                b_blend = blend;
                b_smooth = smooth;
                if(b_matrix && b_color && b_blend && b_smooth != null){
                        options = true;
                }
        }
        
        //-----create bitmapData from an image in the libraray with linkage ID-----//
        public function createFromLibrary(id:String):BitmapData
        {
                var bitmap:BitmapData = BitmapData.loadBitmap(id);
                var mc = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
                mc.attachBitmap(bitmap, 100, "never", true);
                return bitmap;
        }
        
        //-----create bitmapData from an externally loaded image-----//
        public function createFromExternal(temp_mc:MovieClip):BitmapData
        {
                var mc = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
                var bitmap = new BitmapData(temp_mc._width, temp_mc._height, true);
                if(options){
                        bitmap.draw(temp_mc, b_matrix, b_color, b_blend, bitmap.rectangle, b_smooth);
                }else{
                        bitmap.draw(temp_mc);
                }
                mc.attachBitmap(bitmap, 100, "never", true);
                temp_mc.removeMovieClip();
                return bitmap;
        }
}

Posted by: Tim Henager | website http://www.timhenager.com
drag and drop
/*------------------------------------------------------------------------------------------------------------
|
| Author: Eric Feminella                                                                                     | Issued: 08.19.05                                                                                           | Copyright (c)2005 www.ericfeminella.com                                                                    | Class: DragnDrop                                                                                           |
-------------------------------------------------------------------------------------------------------------/
|
| Instantiate new instance of DragnDrop class as follows:
| var varname:DragnDrop = new DragnDrop(dragObj, targetObj, _enabled, _alpha, _visible, _play, _mainPlay);
|                                                                                                            |
| Arguments for constructor are as follows:
| 1.) dragObj:Object = Object to drag
| 2.) targetObj:Object =  Target Object
| 3.) _enabled:Boolean =  Disable Drag Object
| 4.) alpha:Number = Change _alpha of Drap Object
| 5.) _visible:Boolean = Visibility of Drag Object
| 6.) _play:Number = Drag Object - play frame number
| 7.) _mainPlay:Number = Main timeline / _level  - play frame number                                         |
|
| Sample:
| var dd:DragnDrop = new DragnDrop(this.circle, this.square, null, 80, true, null, null);
|                                                                                                            |
-------------------------------------------------------------------------------------------------------------*/



class DragnDrop

{
        
        private var drag:Object;
        private var target:Object;
        private static var _this:Object;
        
        private var drag_x:Number;
        private var drag_y:Number;
        private var target_x:Number;
        private var target_y:Number;
        private var enabled:Boolean;
        private var alpha:Number;
        private var visible:Boolean;
        private var dragPlay:Number;
        private var mainPlay:Number;
        
        
        
        // constructor for DragnDrop class - dragObj, targetObj, _enabled, _alpha, _visible, _play, _mainPlay
        function DragnDrop(dragObj:Object, targetObj:Object, _enabled:Boolean, alpha:Number, _visible:Boolean, _play:Number, _mainPlay:Number) {
                DragnDrop._this = this;
                this.drag = dragObj;
                this.target = targetObj;
                this.drag_x = dragObj._x;
                this.drag_y = dragObj._y;
                this.target_x = targetObj._x;
                this.target_y = targetObj._y;
                this.enabled = _enabled;
                this.alpha = alpha;
                this.visible - _visible;
                this.dragPlay = _play;
                this.mainPlay = _mainPlay;
                build();
        }
        
        
        private function build():Void {
                this.drag.onPress = function() {
                        DragnDrop._this.Drag();
                };
                this.drag.onRelease = function() {
                        DragnDrop._this.Drop();
                };
        }
        
        
        private function Drag():Void {
                this.drag.startDrag();
        }
        
        
        private function Drop():Void {
                this.drag.stopDrag();
                if (eval(this.drag._droptarget) == this.target) {
                        this.drag.enabled = this.enabled;
                        this.drag._alpha = this.alpha;
                        this.drag.gotoAndPlay(this.dragPlay);
                        this.drag._visible = this.visible;
                        this.drag._x = this.target_x;
                        this.drag._y = this.target_y;
                        gotoAndStop(mainPlay);
                } else {
                        this.drag._x = this.drag_x;
                        this.drag._y = this.drag_y;
                }
        }
        
}

Posted by: elaine | website http://www.ultrashock.com
e (Static AS3 Debugger Class)
/**
* @author: Eric Feminella
* @version 1.1
* @copyright: http://www.ericfeminella.com
*/

package {
        
        import flash.net.LocalConnection;
        import flash.events.StatusEvent;
        import flash.net.navigateToURL;
        import flash.net.URLRequest;
        import mx.controls.Alert;
        
        public final class e {
                
                public static function trace(objectToTrace:Object, recursivelyTraceOnce:Boolean = false, recursivelyTraceAll:Boolean = false):void
                {
                        var conn:LocalConnection;
                        conn = new LocalConnection();
                        
                        if (recursivelyTraceOnce)
                        {
                                TraceObject.filterObject(objectToTrace, recursivelyTraceAll);
                        }
                        conn.send("myConnection", "lcHandler", objectToTrace);
                        conn.addEventListener(StatusEvent.STATUS, onStatus);
                }
                
                
                public static function show(messageStr:String):void
                {
                        Alert.show(messageStr);
                }
                
                public static function alert(messageStr:String):void
                {
                        var request:URLRequest = new URLRequest("javascript:alert('Message:  \n" + messageStr + "')");
                        navigateToURL(request);
                }
                
                private static function onStatus(event:StatusEvent):void
                {
                        switch (event.level)
                        {
                                case "status":
                                //trace("LocalConnection.send() succeeded");
                                break;
                                case "error":
                                Alert.show("LocalConnection.send() failed");
                                break;
                        }
                }
        }
}

Posted by: Eric Feminella | website http://www.ericfeminella.com
EnumeratedType
/**
* @author: Eric Feminella
* @url: http://www.ericfeminella.com
* @copyright: (c)2004 - 2006 code.ericfeminella.com
*/


dynamic class EnumeratedType {
        
        public function EnumeratedType()
        {
                for (var i = 0; i < arguments.length; i++) {
                        this[arguments[i]] = i;
                }
        }
}

Posted by: Eric Feminella | website http://www.ericfeminella.com
IntervalMethodCall
/**
* @author: Eric Feminella
* @url: http://www.ericfeminella.com
* @class: IntervalMethodCall
* @usage: makes a method call on an object for a given amount of time
* @updates: Version 2.0 will allow for multiple params to be passed
* @param: Constructor: takes an object(generic object or class),
                                       * method(String), params(String), maximum(number) calls and duration(seconds)
* @param: beginInterval [method] begins method call
* @example:
*    var methodCallTest:IntervalMethodCall = new IntervalMethodCall(this, "functionCallTest", "hello World", 12, .5);
*    this.methodCallTest.beginInterval();
*    function functionCallTest(str){
*       trace(str);
*    }
*/





class IntervalMethodCall
{
        
        
        private var intervalId:Number;
        private var methodCallInterval:Number;
        
        private var scope:Object = {};
        private var method:String;
        private var param:String;
        
        private var count:Number = 0;
        private var maxCount:Number;
        private var duration:Number;
        
        
        
        public function IntervalMethodCall(scope:Object, method:String, param:String, maxCount:Number, duration:Number)
        {
                this.scope = scope;
                this.method = method;
                this.param = param;
                this.maxCount = maxCount -1;
                this.duration = duration * 1000;
        }
        
        
        
        public function beginInterval():Void
        {
                if (this.intervalId != null) {
                        clearInterval(this.intervalId);
                        clearInterval(this.methodCallInterval);
                }
                this.methodCallInterval = setInterval(this.scope, this.method, this.duration, this.param);
                this.intervalId = setInterval(this, "executeCallback", this.duration);
        }
        
        
        
        public function executeCallback():Void
        {
                if (this.count >= this.maxCount)
                {
                        clearInterval(this.intervalId);
                        clearInterval(this.methodCallInterval);
                        this.count = 0;
                }
                
                this.count++;
        }
}

Posted by: Eric Feminella | website http://www.ericfeminella.com

Next 5

Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.