PNGSequence Javascript Class

Monday, April 18th, 2011

I wrote this Javascript class a while back, but have yet to use it. I believe it still could have some use for someone looking to do animation on a transparent (or non) PNG sprite.

Get PNGSequence class

Demo:

http://www.daleyjem.com/projects/js/pngsequence/

Usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var pngSequence;
   
function init()
{
    // A <div> container with an id "tester"
    var tester = document.getElementById("tester");
   
    // img url, sprite width, sprite height, number of frames in sequence
    pngSequence = new PNGSequence("run_cycle.png", 60, 70, 27);
    pngSequence.runLoop();
    // pngSequence.runOnce();
    pngSequence.addTo(tester);
}

function decreaseSpeed()
{
    if (pngSequence.speed + 10 >= 1000) return;
    pngSequence.speed += 10;
}

function increaseSpeed()
{
    if (pngSequence.speed - 10 <= 0) return;
    pngSequence.speed -= 10;
}

ExternalImage Actionscript class demo

Friday, January 7th, 2011

Get ExternalImage class

Features:
- Smoothing support
- Right-click “Save Image as…” and “View Image” options

Demo:

Usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package
{
    import com.daleyjem.as3.ExternalImage;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.ProgressEvent;
   
    /**
     * ...
     * @author Jeremy M. Daley
     */

    [SWF(width="300", height="300")]
    public class Main extends Sprite
    {
        private var imageURL:String = "http://daleyjem.com/wp/wp-content/uploads/2010/06/iphone_4_map.jpg";
        private var image:ExternalImage;
       
        public function Main():void
        {
            if (loaderInfo.parameters.imageURL != null) imageURL = loaderInfo.parameters.imageURL;
            // url, smoothing = true, display right-click context menu options = true
            image = new ExternalImage(imageURL, true, true);
            image.addEventListener(ProgressEvent.PROGRESS, onImageLoadProgress);
            image.addEventListener(Event.COMPLETE, onImageLoaded);
        }
       
        private function onImageLoadProgress(e:ProgressEvent):void
        {
            trace(e.bytesLoaded / e.bytesTotal);
        }
       
        private function onImageLoaded(e:Event):void
        {
            image.width = stage.stageWidth;
            image.height = stage.stageHeight;
            addChild(image);
        }
    }
}