Journal entries from December, 2008
Categories: Flash , Actionscript

so I needed to record a double click in flash for a project and went looking for code.

wow. there's a lot of convoluted and LONG code out there for such a simple thing! recording a double click shouldn't require 30 lines of code. if it does, you're doing something seriously wrong.

 

here's MY actionscript 2 (AS2) code for detecting a double click in flash if you want to change the speed at which you want to detect make 'double_click_wait' higher or lower. 11 lines of code is all you should need.

 

//mouse double click
var double_click_wait = 300;
var lastClick = 0;
var mouseListener:Object = new Object();
mouseListener.onMouseUp = function() {
	if ((getTimer()-previousClick) < double_click_wait) {
		trace("mouse double click ");
		previousClick = 0;
	}
	previousClick = getTimer();
};
Mouse.addListener(mouseListener);

 
Category: Uncategorized

This code is meant for pls files but could easily be adapted for m3u. no benefit I can see in doing that though compared to pls.

-----

So for a little personal project I'm doing in flash I'm building an mp3 player.

Playing mp3's with flash is pretty easy and and making some buttons with play pause etc is also not really an issue. But loading a playlist file... well now we have a problem.

Most people seem to want to just creat an xml file becuase flash does that easily. But that seems like a little lazyness at the start and alot of tedious work down the road creating xml files all the time. I'd rather not have all that extra work later on and I'd rather have native support of .pls files for playing music.

I googled and couldn't find anyone who got this running except some guy, ming chan with m3u years ago, but the source is since gone and disapeared. So for anyone who's also stuck, please feel free to use my actionscript code, but if you improve it (It's messy I know...) please post in the comments.

Anyways here's the source code for parsing a .pls file in actionscript2.

//used to clean up the playlist -meant to work exact same as // php str_replace. I hate that flash doesn't have it. function str_replace(search, replace, string) { var array = string.split(search); return array.join(replace); } //////lets open the .pls file and load it into memoriez! var scope:MovieClip = this; var arr:Array = new Array(); var myLoadData:LoadVars = new LoadVars(); myLoadData.load("test.pls"); myLoadData.onData = function(success) { /* .pls files use groups of 3. first file location, then track name, then the length of character sin the track name. not really any need for the 3rd one. but who knows. */ arr = success.split("\n"); ////////////// mp3_playlist_file_location_array = new Array(); mp3_playlist_file_title_array = new Array(); mp3_playlist_item_counter = 0; current_track_number = 1; //don't start at zero for (var a = 1; a<arr.length; a++) { mp3_playlist_item_counter++;//first is 1 if (mp3_playlist_item_counter == 1) { //file location cleaned1 = arr[a]; cleaned1 = cleaned1.str_replace('File'+ current_track_number + '=', 'C:'); cleaned1 = str_replace('File' + current_track_number+'=', 'C:', cleaned1); mp3_playlist_file_location_array.push(cleaned1); } else if (mp3_playlist_item_counter == 2) { //title cleaned2 = arr[a]; cleaned2 = str_replace('Title' + current_track_number+'=', '', cleaned2); mp3_playlist_file_title_array.push(cleaned2); } else if (mp3_playlist_item_counter == 3) { //is this even used? length = number of chars in title. mp3_playlist_item_counter = 0; current_track_number++; } } /* insert your own function here that uses these 2 arrays. only here doing so outside of the function would mean it would be called BEFORE we parse the data */ //my_function_to_use_this_data(); };

 

It's pretty raw and brute force, but it works just fine. You have 2 string arrays at the end, one with the file location and one with the id3 name. unfortunetly track time isn't in a .pls file (it's also not in an m3u either) so you have to read that on your own with another function. ...maybe I'll post that after I write it.

 
Categories: Work , Programming

Like beer? who doesn't? I just finished working on the current Stella Artois.com website for xmas, it was designed here at my work (Lowe Roche) by us and Dan Purdy an uber talented flash guru.  Beyond doing a bulk of the xml and php code that runs it I also designed the printable paper ornaments you see there (the bird and star).

 

 

Go try printing them out. they're free and fun!

it was also a great exercise in 3ds max to foldable form construction and just a fun break from my usual programming heavy job.

Stellaartois.com

 
Categories: Art , Internet , Genpets

all emails originally sent to genpets.com also go to my database. (replies from me or them don't). November 2008 had 3017 emails alone. and I tried to reply to most of those!!

if you're stumbling accross this site and are curious, check out www.brandejs.ca/gp_emails.php

 


Page 1 of 1