Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Actionscript _Animate Class

This is basically a way to set up an animation queue to utilize scripted tweening. You would have to create external functions which carry forth the animation actions then store the function objects in the _Animate.queue Array in the sequence you wish to play them out. Ideally, these functions would return a Tween object for the sake of utilizing "onMotionStopped". Returning False (bool) will simply allow the next function in the queue to fire without checking for the onMotionStopped call. When you are ready to start the animation sequence, just call launch();

import _String;

dynamic class _Animate {
	var queue:Array;
	
	function _Animate() {
		queue = null;
	}
	
	public function caller(qNum){
		var gA = this;
		var callback = queue[qNum].func.apply(this, _String.toArray(queue[qNum].params)); qNum++;
		if (qNum < queue.length && callback) callback.onMotionStopped = function() { gA.caller(qNum); }
		else if (qNum < queue.length && !callback) gA.caller(qNum);
	}
	
	public function launch(){ caller(0); }
	
	
}


Sample Usage

var zoomIn = new _Animate();

zoomIn.queue = [
	{func:aniSidebar, params:"hide,6"},
	{func:aniMapMidFade, params:"hide,6"}
];

zoomIn.launch();

function aniSidebar(action, time){
	var leftBeginX = (action == "hide") ? 0 : 0 - sidebarLeftBg._width;
	var leftEndX = (action == "hide") ? 0 - sidebarLeftBg._width : 0;
	var rightBeginX = (action == "hide") ? Stage.width - sidebarRightBg._width : Stage.width;
	var rightEndX = (action == "hide") ? Stage.width : Stage.width - sidebarRightBg._width;
	var transition = mx.transitions.easing.Regular.easeInOut;
	var leftAni = new mx.transitions.Tween(sidebarLeftBg, "_x", transition, leftBeginX, leftEndX, time);
	var rightAni = new mx.transitions.Tween(sidebarRightBg, "_x", transition, rightBeginX, rightEndX, time);
	return rightAni;
}

function aniMapMidFade(action, time){
	var begin = (action == "hide") ? 100 : 0;
	var end = (action == "hide") ? 0 : 100;
	var transition = mx.transitions.easing.Regular.easeOut;
	var mapMidAni = new mx.transitions.Tween(mapMid, "_alpha", transition, begin, end, time);
	return mapMidAni;
}

Javascript Motion tween

// description of your code here
// Motion tween

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

  <script type="text/javascript">
      var pos=0;

        function move(){
            pos = 0;
            changeInnerHtml();
            setTimeout('move()',1000);
            pos = 0 ;

        }

        function changeInnerHtml()
        {

              pos = pos +5;
              document.getElementById('spid').style.visibility = 'hidden';
//              document.getElementById('div1').style.visibility = 'hidden';

              if( pos <= 200 )
              {

                  document.getElementById('b1').style.left = pos + 'px';
                  setTimeout("changeInnerHtml()",10);

              }

              
           }
          

                    
//            document.getElementById('div1').innerHTML = '';
//            document.getElementById('div1').innerHTML = '<input type = "text" name = "hi" />' ;                      }
       

  </script>

  <style type="text/css">
      .divstyle
      {

         width:50px;
         height:50px;
         position:relative;
         left:100px;
         border:1px;
         visibility:visible;

          
      }
      
  </style>
  <title></title>
</head>
<body>

    <div id="div1">
        <span id="spid" class="divstyle">
            hi
        </span>
        <input type="submit" id="b1" name="b1" onclick="move()" class="divstyle"/>
        <iframe id="iframe1" class="div1" >
            
        </iframe>
    </div>

</body>
</html>

Coding a tween

//Tween an object's _y property. This is within the context of a v2 Component, but the same principles also apply elsewhere. Just replace 'this' with the movie clip you want to tween.

import mx.transitions.Tween;
import mx.transitions.easing.*;


var tween = new Tween(this, "_y", Elastic.easeOut, y, yToMoveTo, 1, true);
tween.onMotionFinished = mx.utils.Delegate.create(this, motionFinished);
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS