Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

<< Prev 5 | Next 5

AS 2.0 : Simpel Animation class

//This is a simpel animation class. It has only FadeIn function.
/*
*
*	Animation.as
*	Simpel animation class
*	Fransjo Leihitu
*	http://www.leihitu.nl
*
*/
dynamic class Animate {
        
        private var objRef:Object;
        var addListener:Function;
        private var parentObj:Object;
        
        /*
        Constructor;
        */
        public function Animate(objRef:Object)
        {
                AsBroadcaster.initialize(this);
                this.addListener(this);
                
                if(objRef!=null)
                {
                        this.objRef=objRef;
                }
        }
        
        function fadeIn(toX:Number,toY:Number,alpha:Number,alphaSteps:Number,speed:Number,margin:Number):Void
        {
                var obj=this;
                
                if(objRef!=null)
                {
                        if(toX==null){
                                objRef.toX=objRef._x;
                        } else {
                                objRef.toX=toX;
                        }
                        
                        if(toY==null){
                                objRef.toY=objRef._y;
                        } else {
                                objRef.toY=toY;
                        }
                        
                        if(alpha!=null) objRef._alpha=alpha;
                        
                        if(alphaSteps==null) alphaSteps=0;
                        objRef.alphaSteps=alphaSteps;
                        
                        if(speed==null) speed=5;
                        objRef.speed=speed;
                        
                        if(margin==null) margin=0.5;
                        objRef.margin=margin;
                        
                        objRef.onEnterFrame=function()
                        {
                                this._x+=(this.toX - this._x) / this.speed;
                                this._y+=(this.toY - this._y) / this.speed;
                                
                                this._alpha+=this.alphaSteps;
                                
                                var diffX:Number=this.toX - this._x;
                                if(diffX<0)
                                {
                                        diffX=diffX*-1;
                                }
                                
                                var diffY:Number=this.toY - this._y;
                                if(diffY<0)
                                {
                                        diffY=diffY*-1;
                                }
                                
                                if( (diffX <= this.margin) && (diffY <= this.margin) )
                                {
                                        this._x=toX;
                                        this._y=toY;
                                        
                                        if(this._alphaSteps!=0)
                                        {
                                                this._alpha=100;
                                        }
                                        
                                        
                                        delete this.toX;
                                        delete this.toY;
                                        delete this.alphaSteps;
                                        delete this.speed;
                                        delete this.margin;
                                        
                                        delete this.onEnterFrame;
                                        
                                        obj.doneAnimated();
                                }
                                
                        }
                } else {
                        var errorStr:String="No target object";
                        obj.error(errorStr);
                }
        }
        
        public function setObj(objRef):Void
        {
                if(objRef!=null)
                {
                        this.objRef=objRef;
                }
        }
        
        private function error(msg:String)
        {
                this.broadcastMessage("onError",msg);
        }
        
        private function doneAnimated()
        {
                this.broadcastMessage("onDone",true);
                delete this.onDone;
        }
} //end class

//On your timeline, create a rectangle, convert it to a MovieClip, and give it a name, for example myRectangle

stop();

import Animate;

var myAnim:Animate=new Animate(this.myRectangle);

myAnim.onDone=function(p_success:Boolean)
{
        trace("done");
}

myAnim.onError=function(msg:String)
{
        trace(msg);
}

myAnim.fadeIn(400,300,0,5,5,0.5);

Posted by: Fransjo Leihitu | website http://www.leihitu.nl
AS3 LocalDebugger
/**
* Copyright (c) 2006 www.ericfeminella.com.
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
                                                                    * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/


package com.ericfeminella.debugger {
        
        import flash.net.LocalConnection;
        import flash.events.StatusEvent;
        import flash.events.ErrorEvent;
        import flash.events.AsyncErrorEvent;
        import mx.controls.Alert;
        
        public final class LocalDebugger {
                
                public static function trace(obj:Object, useRecursion:Boolean = false):void
                {
                        var connection:LocalConnection = new LocalConnection();
                        
                        if (useRecursion)
                        {
                                LocalDebuggerTraceHelper.iterate(obj, useRecursion);
                        }
                        connection.send(LocalConnectionSettings.CONNECTION_NAME, LocalConnectionSettings.CONNECTION_METHOD, obj);
                        connection.addEventListener(StatusEvent.STATUS, onStatus);
                        connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onASYNCFault);
                }
                
                public static function show(message:String):void
                {
                        Alert.show(message);
                }
                
                private static function onStatus(event:StatusEvent):void
                {
                        if (event.level == ErrorEvent.ERROR)
                        {
                                Alert.show(event.toString());
                        }
                }
                
                private static function onASYNCFault(asyncError:AsyncErrorEvent):void
                {
                        Alert.show(asyncError.toString());
                }
        }
}

Posted by: Eric Feminella | website http://www.ericfeminella.com
Automatic scroller of dynamic text
//This script will scroll any size box of text w/ any size text, unless it is
//too small to scroll. When it reaches the end of the scroll length, it
//"bounces" back to the top after a delay, very easy...(i've only been doing
//this for 3 days, somewhat difficult for me) put the text in like the 1st frame
//or something like that...works great! (working on a complex "smooth" version)
//PS, works great with wordwrap on or off!!!

//START script

scrollerSolved = false
goBackwards = false
APause = setInterval(ScrollBaby, 750);
//calls a function called ScrollBaby every 500 hundreths of a second
//(or .5 second)

function ScrollBaby() {
        if (goBackwards != true) {
                _root.textInstance.scroll += 1;
        }
        if (goBackwards == true) {
                _root.textInstance.scroll -= 1;
        }
        //the actual "moving" of the text
        if (scrollerSolved != true) {
                numberOfLinesExisting = _root.text.scroll;
                numberOfLinesCounted += 1;
                if (numberOfLinesExisting<=numberOfLinesCounted) {
                        numberOfLinesCounted = numberOfLinesExisting;
                        goBackwards = true;
                        scrollerSolved = true;
                }
        }
        //my algorithm to get the length of the text in the field in lines
        temp = _root.text.scroll;
        if (temp == numberOfLinesCounted ) {
                goBackwards = true;
                setInterval(null, 2000) //bounce delay
        }
        if (1 == _root.text.scroll) {
                goBackwards = false;
                setInterval(null, 2000)	//bounce delay
        }
}

Posted by: Alex Songe | website http:\\www.galileo.spaceports.com/~dths/
basic scroll text
texto="Copia aquí el texto que deseas scrolear. Paste the text to scroll here"

up.onRelease = function() {
        texto.scroll -= 1;
};

dwn.onRelease = function() {
        texto.scroll += 1;
};

Posted by: aRiel | website http://www.3x3interactive.com
BenchMark
_global.BMark=new Object();
_global.BMark.start=function(ID){
        if(this[ID].$start==null){ this[ID]={$start:getTimer()} }
};
_global.BMark.stop=function(ID){
        this[ID].$final=getTimer();
        this[ID].$elapsed=this[ID].$final - this[ID].$start;
        if(this[ID].$elapsed<=59999) trace(this[ID].$elapsed/1000);
        else trace(this[ID].$elapsed/1000/60);
        delete this[ID];
};

Posted by: Red Penguin | website http://www.komielan.com

<< Prev 5 | Next 5

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