Using JSONP from ActionScript

ActionScript3 doesn’t have JSON/JSONP(JSON with Padding) official API, but JSON library is include as3corelib. But yet JSONP library is nothing now, so I made JSONPLoader interface likes URLLoader.

Source

JSONPLoader.as (The MIT Licence)

Example Code

AS3 code

JSONPLoader.allowCurrentDomain(); // Allow show browsing url's domain.
var loader:JSONPLoader = new JSONPLoader();
loader.addEventListener(Event.COMPLETE, function(e:Event):void {
    trace(e.target.data);
});
loader.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void {
    trace('error!');
});
// loader.callbackQueryName = 'callback'; // Default name is "callback"
// load delicious's JSONP url
loader.load('http://del.icio.us/feeds/json/url/data?hash=46efc577b7ddef30d1c6fd13311b371e');

And need to set html paramater.

<param name="allowScriptAccess" value="always" />
Posted at 8pm on 10/04/07 | 2 comments | Filed Under: ActionScript read on

Accurate bezier special property for Tweener

Tweener has a bezier special property(_bezier). The propety is very useful. But _bezier property can’t produce accurate bezier curve if there’re more than three points (cubic bezier).

Sometimes I want to use accurate bezier curves on Tweener, so I hack up ‘_accurate_bezier’ special property.

DEMO

  • Double Click
    • Add Bezier Point
  • Bezier Point Drag
    • Move Bezier Point

This movie requires Flash Player 9
source

CODE

Register special property

Tweener.registerSpecialPropertyModifier("_accurate_bezier", SpecialPropertiesDefault._bezier_modifier, _accurate_bezier_get);

_accurate_bezier_get function’s implemention

public static function _accurate_bezier_get(b:Number, e:Number, t:Number, p:Array):Number {
    var tm:Number = 1 - t;
    if (p.length == 1) {
        // quadratic bezier curves
        return b + t*(2*(tm)*(p[0]-b) + t*(e - b));
    } else if (p.length == 2) {
        // cubic bezier curves
        return b*tm*tm*tm + 3*p[0]*t*tm*tm + 3*p[1]*t*t*tm + e*t*t*t;
    } else {
        // more points curves
        var points:Array = [b];
        points = points.concat(p);
        points.push(e);
        var res:Number = 0;
        var len:uint = points.length;
        var pos:Number, tmp:Number, a:Number, b:Number, c:Number;
        for (var i:uint=0; i < len;i++) {
            pos = points[i];
            tmp = 1.0;
            a = len - 1;
            b = i;
            c = a - b;
            while (a > 1) {
                if(a > 1) tmp *= a; a -= 1;
                if(b > 1) tmp /= b; b -= 1;
                if(c > 1) tmp /= c; c -= 1;
            }
            tmp *= Math.pow(t, i) * Math.pow(tm, len -1 -i);
            res += tmp * pos;
        }
        return res;
    }
}
Posted at 10pm on 10/03/07 | 5 comments | Filed Under: ActionScript, Tweener read on

JSTweener release!

http://coderepos.org/share/wiki/JSTweener

I released JSTweener that is Motion Tween library for JavaScript. JSTweener API likes Tweener and using Tweener’s easing functions(port to JavaScript).

DEMO

JSTweener Motion Typography

Examples

API likes Tweener.

JSTweener.addTween(element.style, {
     time: 3,
     transition: 'linear',
     onComplete: function() {},
     width: 200,
     height: 200,
     left: 500,
     top: 300
 });

and that can using suffix option.

JSTweener.addTween(element.style, {
     time: 3,
     transition: 'linear',
     onComplete: function() {},
     width: 200,
     height: 200,
     left: 500,
     top: 300,
     suffix: {
       width: 'px',
       left: 'pt'
     }
 });

enjoy!

Posted at 12am on 10/02/07 | 1 comment | Filed Under: JavaScript, Tweener read on

I start writing this blog in English.

Hi all.

I start writing this blog in English.

Because I want to improve my English skill and I’ll publish some tools, libraries, and more.

Posted at 10pm on 10/01/07 | no comments | Filed Under: Uncategorized read on

Categories