Script

Filter
2007-09-04

Praktiskt Tweening

Flash
Använd yoyo() för att göra en kontinuerlig animation
/*
You can make an animation continue animating back and forth without stopping.
The Tween class accommodates this kind of animation with the aptly named yoyo() method.
The yoyo() method waits for the onMotionFinished event handler to execute, and then it
reverses the begin and finish parameters. 
*/

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

var box_tween:Object = new Tween(box_mc, "_x", Regular.easeInOut, 0, Stage.width-box_mc._width, 1, true);
box_tween.onMotionFinished = function() {
    box_tween.yoyo();
};
2007-09-04

Transitions och tweening med actionscript

Flash
Kombinera tweening och transitions
/*
You can generate some interesting effects when you combine the Transition and Tween classes.
You can use the Transition class to move a movie clip along the X-axis while you adjust the
same clip's _alpha property using the Tween class. Each class can use a different easing method,
which means there are many animation possibilities for objects in your SWF files. You can take
advantage of the Tween class' continueTo() and yoyo() methods, or the onMotionFinished event
handler to create a truly unique effect.
*/

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

var mcl_obj:Object = new Object();
mcl_obj.onLoadInit = function(target_mc:MovieClip) {
    new Tween(target_mc, "_alpha", Strong.easeIn, 0, 100, 2, true);
    TransitionManager.start(target_mc, {type:Fly, direction:0, duration:3, easing:Elastic.easeInOut, startPoint:6, param2:empty});
};

var my_mcl:MovieClipLoader = new MovieClipLoader();
my_mcl.addListener(mcl_obj);
my_mcl.loadClip("http://www.rosiro.se/UserFiles/Image/logo.gif", this.attachMovie("imgHolder_id", "img_mc", this.getNextHighestDepth()));
2007-09-04

Styr animationen med actionscript

Flash
Få nåt att hända när animationen är slut med onMotionFinished
/*
You can write an event handler that triggers when the animation completes.
*/

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

var tween_handler:Object = new Tween(ball_mc, "_alpha", Strong.easeIn, 100, 0, 3, true);
tween_handler.onMotionFinished = function() {
    trace("onMotionFinished triggered");
};
2007-08-23

Simple slideshow

Javascript
Simple slideshow
<html>
<head>
<script type="text/javascript">
var imgs = new Array("img1.jpg", "img2.jpg", "img3.jpg");
var cnt = 0;
function change(direction) {
    if (document.images) {
        try {
            if (isNaN(direction)) {
                throw "error1";
            }
            cnt += direction;
            if (cnt < 0) {
                cnt = imgs.length - 1;
            } else if (cnt > imgs.length - 1) {
                cnt = 0;
            }
            document.holder.src = imgs[cnt];
        } catch (err) {
            if (err == "error1") {
                alert("Error: No number...");
            }
        }
    }
}
</script>
</head>
<body>
<img src="img1.jpg" name="holder" alt="" height="300" width="400" /><br />
<a href="javascript:change(-1)">&laquo; Prev</a> 
&nbsp; &nbsp;
<a href="javascript:change(1)">Next &raquo;</a>
</body>
</html> 
2007-08-23

Switching images

Javascript
Swithcing images in a time interval
<html>
<head>
<script type="text/javascript">
var imgs = new Array("img1.gif", "img2.gif", "img3.gif");
var nr = 0;
var urls = new Array("www.mysite.com", "www.yoursite.com", "www.hissite.com");
function rotate() {
    if (document.images) {
        if (document.my_img.complete) {
            nr++;
            if (nr == imgs.length -1) {
                nr = 0;
            }
            document.my_img.src = imgs[nr];
        }
        setTimeout("rotate()", 3000);
    }
}
function changeLoc() {
    document.location.href = "http://" + urls[nr];
}
</script>
</head>
<body onload="rotate();">
<a href="javascript:changeLoc();"><img src="img1.gif" name="my_img" alt="" border="0" /></a> 
</body>
</html> 
🙂