Home » ActionScript 3.0, AIR, Android, Flash CS4, Flash CS5

TinyUrl with actionscript 3.0 | Create TinyURL with as3

28 February 2011 One Comment
Share on Facebook

TinyUrl is a url shortener such as bit.ly or TinyUrl to share your favorite blog posts and links on the network.

Actionscript – as3 version of TinyUrl creation:

import flash.events.*
import flash.net.*;
import flash.net.URLVariables;

var variables:URLVariables = new URLVariables();
variables.url = String("http://www.designscripting.com");
sendAndLoad("http://tinyurl.com/api-create.php", variables)

function sendAndLoad( url:String, _vars:URLVariables ):void {

	var request:URLRequest = new URLRequest(url);
	var _urlloader:URLLoader = new URLLoader();
	_urlloader.dataFormat = URLLoaderDataFormat.TEXT;
	request.data = _vars;
	request.method = URLRequestMethod.POST;
	_urlloader.addEventListener(Event.COMPLETE, handleComplete);
	_urlloader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);

function handleComplete(event:Event):void {
	var loader:URLLoader = URLLoader(event.target);
	trace("TinyURL: " + loader.data);
function onIOError(event:IOErrorEvent):void {
	trace("Error loading URL.");

In the above Actionscript code change the URL string and run the application to generate the shortened Url.

variables.url = String("http://www.designscripting.com");

We are calling “api-create.php” server-side page, with URL as parameter.

sendAndLoad("http://tinyurl.com/api-create.php", variables)

And the result is shortened Url.

trace("TinyURL: " + loader.data);



We don't share your email anywhere, grab our rss via feedburner

One Comment »

  • Masamune said:

    Works pretty fine, thanks a lot

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.