PaperKingdoms

September 9, 2009

Bit.ly in AS3

Filed under: actionscript, code, flash, internet, web development — bardicknowledge @ 8:42 am

I know this is pretty damn simple, but in case you’re in a hurry here’s a quick example of using bit.ly in as3 i whipped up. This is really just the basics. I will likely expand on it, but you can get the gist.

  1. Download as3corelib : http://code.google.com/p/as3corelib/
  2. Sign up with bit.ly : http://bit.ly/account/register?rd=/
  3. That’s pretty much it….


import com.adobe.serialization.json.JSON

var login:String = "put your bit.ly login here";
var api:String = "put your bit.ly api key here. It's on your account details page";
var url:String = escape("the url you want to shorten");
var bitly:String = "http://api.bit.ly/shorten?version=2.0.1&longUrl="+url+"&login="+login+"&apiKey=" + api;

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, completeHandler);
loader.load(new URLRequest(bitly));

function completeHandler(ev:Event):void
{
var bitlyObj:Object = JSON.decode(ev.target.data);
var o:Object = bitlyObj.results[url];
if(bitlyObj.statusCode == "OK")
{
trace("Success! Short URL is : " + bitlyObj.results[url].shortUrl);
}
}

That’s pretty much it. I didn’t write my error handling yet, but it’s pretty simple. Just trace out ev.target.data to see the JSON structure in case you need more details ^^

Hope it helps

*Updated to add the escape to the URL.

July 31, 2007

mp3 player – ActionScript

Filed under: actionscript, code, design, flash, internet, music, open source, software, tech, web development, XML — bardicknowledge @ 8:07 am

Hey for anyone that reads this. It has been a little bit, but I have a new code snippet for ya’s. It’s a pretty simple mp3 player that you could easily embedded on a site.

Here’s there script (link). It uses a pretty simple XML also.

<song>
<t st=”songtitle” l=”url” a=”artist” />
</song>

Give it a whirl. I will be trying to remake it with a slider on the next version and make it smaller.

July 17, 2007

Fade background color in new color : actionscript

Filed under: actionscript, code, design, flash, internet, open source, program, software, tutorial, web development — bardicknowledge @ 9:53 am

Have ya ever wanted to change your background color during runtime using actionscript instead of having a timeline event? Did you by any change want to have it fade from it’s current color to the new color with the click of a button?

Well, if so today’s your lucky day. For a site I’m working on I needed to make the buttons when clicks change the background color, so I set out to do it. The first and pretty much only problem I encountered was when you changed the background it would show the stage background and not the last color showed. So if I click red and then clicked orange I would want it to fade from red to orange. Well what I was getting was red, white, then fade to orange. But after about 15 minutes or so of playing I figured out a way around it.

So anyways, it works now and you can easily change the speed of fade by changing the alpha added to itself. Here’s the link. Hope it’s of some use to ya’s ^_^

July 16, 2007

XML driven drop down menu

Filed under: actionscript, design, web development, XML — bardicknowledge @ 10:47 am

Well I’m working from home today, and I has given the task of creating a XML driven drop down menu. Now, I have been trying to figure this one out for a while and I think I have finally figured out a way to finally pull it off. My biggest problem has been actually making the url go somewhere since I was building the clip within a clip. After trying to figure out a way to use an inner clips mouse events and failing I moved on to just creating a bunch of MCs.

Which worked except that the menus wouldn’t stay open. But I think I figured it out! I think if I use a hit test to see if I’m over one of the sub menus it should work.

I will of course post my code up as soon as I get it working.

July 13, 2007

coding habits

Filed under: actionscript, blog, musings, program, software, tech, web development — bardicknowledge @ 1:10 pm

so I’ve been thinking about my coding habits lately, mainly because I am going to shortly leap into a rather large project: scripting a web based game by my lonesome. and as I was thinking about my technique, I started to think about the web development course I just finished a few months ago.

thinking back, if I  had the chance I would have pushed my teacher more to teach how to properly create code. every time we started a new project I would pester the teacher to explain how I could write code once and have it work. basically, though I didn’t know at the time, I was asking him to teach me how to make functions and classes that could be used and  reused.

this stems from my thoughts that code should only need to be written once for maximum speed/efficiency. and I still think this after scripting tight out for the last four months for a small web development company. you may be thinking well I can write that code with more ease if I just use a lot of if’s or repetition. but you’re wrong my fine friends who believe this. after you learn to write code using functions (I haven’t learned classes yet :S ) your productivity, ease of maintenance and overall better code levels will increase.

you should also not forget includes! for instance this morning I had 8 files to edit a script to that would read children from a XML file, turn them into links and spit em on the page. Then on click bring up a corresponding child. I wrote a 50 line script and saved it three times.  I could have done it the once, but that could have meant ripping someone else’s FLA apart and would have taken about another hour or two. So instead I edited 1 number in each of the external AS scripts and included them into the fla they related to. And done.

far easier than and faster than writing the same thing without a loop or without the includes.

so if you  have the time, and if you don’t I suggest you make it, go and spend some time learning to make coding reusable and more efficient. It will make you far more productive in the long run.

Older Posts »

Create a free website or blog at WordPress.com.