PDA

View Full Version : Useful Utilities..cookies, key combination,etc


MichaelxxOA
01-27-2006, 03:20 AM
Here is a quick linked list of some useful utilities

Coming Soon!

I am in the process of putting together a Dev Kit of some classes that I use, and I'm working on classes that I will be using in the near future. I can't distribute source code yet because I want to wait until I have a strong set before releasing the first iteration, but I am giving you guys the documentation which can be found here...

This is everything that is currently implemented in the dev kit:
http://www.createage.com/as2docs/createage (http://www.createage.com/as2docs/createage)

EventBroadcaster
http://www.actionscript.org/forums/showthread.php3?t=112186

TabOrderManager
http://www.actionscript.org/forums/showthread.php3?t=112023

Sound Manager
http://actionscript.org/forums/showthread.php3?t=111957

Background
http://www.createage.com/blog/?p=83

Stack/Queue Data Structures
http://www.actionscript.org/forums/showthread.php3?t=104006

Depth Manager
http://www.actionscript.org/forums/showthread.php3?t=103699

Interval Manager
http://www.actionscript.org/forums/showpost.php3?p=473121&postcount=1

Double Click
http://www.actionscript.org/forums/showpost.php3?p=443591&postcount=1

QueryString
// works in Safari thanks to Buginajar
http://www.actionscript.org/forums/s....php3?t=119964
// old
http://www.actionscript.org/forums/showpost.php3?p=449131&postcount=2

Cookie Jar
http://www.actionscript.org/forums/showpost.php3?p=450216&postcount=25

String Format
http://www.actionscript.org/forums/showpost.php3?p=457851&postcount=34
http://www.actionscript.org/forums/showpost.php3?p=459613&postcount=55

Key Combinations
http://www.actionscript.org/forums/showpost.php3?p=459547&postcount=39

Drawing Utility
http://www.actionscript.org/forums/showpost.php3?p=459557&postcount=48

Custom Cursor
http://www.actionscript.org/forums/showpost.php3?p=459614&postcount=56

Timer
http://www.actionscript.org/forums/showpost.php3?p=459827&postcount=58

Configuration Utility
http://www.actionscript.org/forums/showpost.php3?p=460411&postcount=60

Decting User Inactivity
http://www.actionscript.org/forums/showpost.php3?p=460852&postcount=78

Undo/Redo Architecture
http://www.actionscript.org/forums/showthread.php3?t=99487

Regular Expressions
http://www.actionscript.org/forums/showpost.php3?p=462215&postcount=94

Date Class... DateTime
http://www.createage.com/blog/?p=45

Assertnfailure's Classes

DataTree class
http://actionscript.org/forums/showthread.php3?t=112197

-------------------------------------------------------------
Along with my Multi Key class I was needing for a recent project, I have also been required to write a few applications that needed some minor double click detection. I took this opportunity to write a very simple class for detecting double clicks. It's really easy to use and has served it's purpose for me, if anyone wants to elaborate on, or use this class.. please feel free. I have included an example of the class and the code in the fla, and also a zip file with a ready example. Take Care.

DoubleClick.as:

import lists.*;
class DoubleClick
{
// the target we are checking if is double clicked
private var target:MovieClip = null;
// the amount of time before the second click doesn't count as a double click
private var DELAY:Number = 300;
// a flag specifying whether or not the first click has been made
private var firstClicked:Boolean = false;
// the id of the interval that gets set to destroy the second click
private var intID:Number;
// the list that stores all objects listening for events
private var listeners : ListenerList;
/* Constructor */
public function DoubleClick(target:MovieClip)
{
this.target = target;
// listen for events from the mouse
Mouse.addListener(this);
listeners = new ListenerList();
}
// is called everytime the users presses the mouse
private function onMouseDown():Void
{
if (target == null || target.hitTest(_xmouse, _ymouse))
{
if (!this.firstClicked)
{
this.firstClicked = true;
intID = setInterval(killInterval, this.DELAY);
}
else if (this.firstClicked)
{
invokeOnDoubleClicked();
this.firstClicked = false;
killInterval();
}
}
}
// destroys the interval, making sure the double click gets destroyed
private function killInterval():Void
{
this.firstClicked = false;
clearInterval(intID);
}

// adding and removing listeners
public function addListener( o : Object ) : Boolean
{
return listeners.addListener(o);
}
public function removeListener( o : Object ) : Boolean
{
return listeners.removeListener(o);
}
// inokes the onDoubleClicked() event in all listeners
private function invokeOnDoubleClicked() : Void
{
for (var i:Number = 0; i<listeners.count; i++)
{
listeners.getListener(i).onDoubleClicked();
}
}
}



FLA code:

var dc = new DoubleClick(test_mc);

_obj = new Object();
_obj.onDoubleClicked = onDC;

dc.addListener(_obj);

function onDC() : Void
{
trace("Double Clicked!");
}



-Michael

MichaelxxOA
02-09-2006, 12:47 PM
Lately I've been sick of the fact that I can't query the get string, dont' know how many other people are having this issue, in any case I wrote a class that doesn't require you to have any javascript in the html, and it's really simple to use, so here it is if you guys wanna improve it feel free, I'll do what I can when I get the time. Which isn't often.

TakeCare.

_Michael


import flash.external.ExternalInterface;
/*
* Created so that I can query values from the get string.
*
*@author: Michael Avila
*/
class URLQuery
{

// Instead of calling a function from javascript
// we will build the function in flash and call it
private var get_url_function:String = "function get_url(){return window.location.toString();}";

// a multi-dimensional array that contains the name value pairs, index[0] is the name and index[1] is the value
private var name_value:Array;

/* constructor */
public function URLQuery()
{

name_value = new Array();
// here we are making the call to our function, and we are taking it's return value, then we are spliting
// it in half at the first ? and taking the right side of the string, then we are spliting into another array
// this array will be split up on all of our & symbols
name_value = ExternalInterface.call(get_url_function).toString( ).split("?")[1].split("&");

buildNameValues();
}

/*
* You pass in the value for the variable, and we will return it if it extists
* if it doesn't we will return null
*/
public function queryString( getVar:String ):String
{
for(var i:Number=0; i<name_value.length; i++)
{
if (name_value[i][0] == getVar) return name_value[i][1];
}
return null;
}


/*
* Builds are name_value array, simple parsing
*/
private function buildNameValues()
{
for (var i:Number=0; i<name_value.length; i++)
{
name_value[i] = name_value[i].split("=");
}
}
}

Cota
02-09-2006, 12:55 PM
Thanks a lot, very good stuff....I can think of at least 6 people that would have killed for this recently.

MichaelxxOA
02-09-2006, 05:10 PM
Thanks Cota, In doing this I think I opened up a whole new idea with writing your javascript functions in flash and running them in flash. This should start giving us an opportunity to take care of usability issues. My next project might be integrating this same idea into a class for handling cookies.. anyway I don't know.

The only downfall to this is that it requires Flash 8. I'm just lucky enough at work that we use Flash 8 only. Take Care.

-Michael

Caravaggio
02-09-2006, 08:12 PM
very curious to play with this, but I get..

"The class or interface 'ListenerList' could not be loaded."

right out of the gate...

Vertigo
02-09-2006, 08:23 PM
check your publish settings..and see if the class path is set properly.

V

Caravaggio
02-09-2006, 08:48 PM
Ok, so this is most certainly because of my lack of knowledge and work with classes, but I did check the Publish settings and pointed it to the 'lists' folder and it says "does not match the class that was imported"

Know I'm probably being boneheaded here, but is that not the fix you suggested?

Chewie
02-09-2006, 09:53 PM
the first line in the DoubleClick class is wrong in the zip file. It sould read import list.*, it actually says import util.*

Either change the first line in the class or rename the directory to util, where the ListenerList class is.

Nice of you to share Michael, I am sure I can make use of this.

MichaelxxOA
02-10-2006, 03:08 AM
http://www.nowtheworld.com/repository/flash/GET/Get.html?main_id=Michael

There's a sample, it is reading the main_id var... the fla can be found here:

http://www.nowtheworld.com/repository/flash/Get/Get.fla

Take Care.
_Michael

Cota
02-10-2006, 03:25 AM
So thing will make FlashVars useless. Pretty damn good.

MichaelxxOA
02-10-2006, 09:58 AM
I am so sorry guys, I do all my experimenting in a folder called ActionScript Experiments.. when I use one I move it to the project I am using it on.. I must've accidentally edited and saved without moving first. Thanks chewie for clearing that up, and please use this in whatever way you guys can. If you have any other ideas for little utilities like this please ask and I'll see what I can do about them. Take Care.

_Michael

MichaelxxOA
02-10-2006, 10:02 AM
lol Cota, we'll see... I certainly hate having to create those flash vars. I'm working on a new version though because I dont' like that I have to instantiate the object, I mean there's only one Query String, so I'm working on having a static queryString() method... It'll be done soon I'm just trying to optimize it as much as I can.. thanks again for the feedback. Take Care.
_Michael

skomi101
02-10-2006, 11:45 AM
Hi,

**Error** \\United\http\probe\url\URLQuery.as: Line 8: The name of this class, 'URLQuery', conflicts with the name of another class that was loaded, 'URLQuery'.
{

Total ActionScript Errors: 1 Reported Errors: 1

why i get this error?? please

Caravaggio
02-10-2006, 01:11 PM
Sahweet!

Thanks for creating this and clearing up the issues I had with it! Many thanks!:D

MichaelxxOA
02-10-2006, 03:35 PM
Is this class in your root class path, or is it in a folder off of your root class path?

What does the file structure look like for your fla and your url, please show me the path that you have them both in. Take Care.

_Michael

MichaelxxOA
02-10-2006, 03:36 PM
No problem, I'm glad you can make good use of it. TakeCare.

_Michael

skomi101
02-10-2006, 04:56 PM
I don’t understand what compiled error cause, but now everything its OK. Thank you anyway.

wizdave
02-10-2006, 06:51 PM
Thanks Cota, In doing this I think I opened up a whole new idea with writing your javascript functions in flash and running them in flash. This should start giving us an opportunity to take care of usability issues. My next project might be integrating this same idea into a class for handling cookies.. anyway I don't know.

The only downfall to this is that it requires Flash 8. I'm just lucky enough at work that we use Flash 8 only. Take Care.

-Michael

Thanks a bunch for showing me this. I took your example and changed the GetCookie and SetCookie functions I had been working on.

Check it out here: http://actionscript.org/forums/showthread.php3?t=96359

MichaelxxOA
02-10-2006, 07:22 PM
wizdave - thanks for the feedback, I'm happy to help in any way I can, I plan on writing a Cookie class that uses these methods, would you like me to message you when it's done and working? Thanks again, and Take Care.


_Michael

newblack
02-10-2006, 07:40 PM
this is badassssssssss with like 200 s's. nice work.

Cota
02-10-2006, 07:42 PM
what else you working on Michael? More good stuff I hope.

MichaelxxOA
02-10-2006, 07:59 PM
newblack - Thankssssss (201 s') ;), I want a link of what you develop with it, lol.

I will have a CookieJar class done in a few hours, I got the day off of work so I'm having fun working with stuff. Is there anything you guys can think of? If so hit me up with it. But to keep you waiting Cota at work I specialize in .net development C# specifically but I enjoy programming Java more than anything, so lately I've been working on creating simple datastructures in actionscript and even more so, smooth database integration in actionscript.. but that battle goes on ;). Anyway take care guys, please give me some ideas.

To Wizdave: I am in no way trying to out-do you with the cookies, I even mentioned it before, I really do need a cookie manager class, :(. I'll post the code in a new thread. Take Care.

_Michael

Cota
02-10-2006, 08:03 PM
So do you have any VB exposure....if so..you might be the person I need to help me finish my Flash Screen Capture ActiveX component.

MichaelxxOA
02-10-2006, 08:31 PM
not really but I can try, I'm pretty good at problem solving, and I'm pretty familiar with .net and .net2. If you get bored hit me up at...

aim: PimpinxxPenguin
yahoo: ofagemichael

Take Care.

_Michael

MichaelxxOA
02-11-2006, 11:56 AM
As promised I am giving you guys my CookieJar class.. this is probably one of the simplest yet most useful utility classes I have written. It's extremely easy to use.. I've included inline with my post the class source and an example use as you would see it in an fla. I've also included a zip file of all the working source. Any feedback would be wonderful. Take Care guys.

_Michael


Code in the class:


import flash.external.ExternalInterface;
/*
* This class was created to manage Cookies from directly within flash
* Here we will eliminate the need to have an environment outside of flash
* maintain our cookies.
*
*@author: Michael Avila
*@version: 1.0
*/
class CookieJar
{

private static var write_cookie:String = "function writeCookie(args){var cookie_string = args[0] + \"=\" + escape(args[1]);alert(cookie_string);switch (args.length){case 3:cookie_string += \"expires=\" + args[2];break;case 4:cookie_string += \"path=\" + args[3];break;case 5:cookie_string += \"domain=\" + args[4];break;case 6:cookie_string += args[5];break;}document.cookie = cookie_string;}";

private static var get_cookie:String = "function getCookie(name){var allcookies = document.cookie;var pos = allcookies.indexOf(name + \"=\");if (pos != -1) {var start = allcookies.indexOf(\"=\", pos) + 1;var end = allcookies.indexOf(\";\", start);if (end == -1) end = allcookies.length;var value = allcookies.substring(start, end);value = unescape(value);return value;}}";

private static var remove_cookie:String = "function removeCookie(name){var cookie = name + \"=\";cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';document.cookie = cookie;}";

public static function setCookie(name:String, value:String, expires:Date, path:String, Domain:String, secure:Boolean):Void
{
ExternalInterface.call(write_cookie, arguments);
}

public static function readCookie(name:String):Object
{
return ExternalInterface.call(get_cookie, name);
}

public static function removeCookie(name:String):Void
{
ExternalInterface.call(remove_cookie, name);
}
}


Code in the .FLA:

import flash.external.ExternalInterface;


CookieJar.setCookie("flash_cookie", "Hello World");
alert("FlashCall: " + CookieJar.readCookie("flash_cookie"));

CookieJar.removeCookie("flash_cookie");
alert("FlashCall: " + CookieJar.readCookie("flash_cookie"));

function alert(value)
{
ExternalInterface.call("alert", value);
}

MichaelxxOA
02-11-2006, 12:14 PM
Note: In order for the examples ( and the class for that matter ) to work you have to run it on a web server. Take Care.

_Michael

This is something with cookies not with the class itself.

astgtciv
02-11-2006, 03:04 PM
Looks interesting, thank you for sharing, Michael...

Electric Dandy
02-11-2006, 03:06 PM
Couldn't open it in MX. Is it 8?

Cota
02-11-2006, 05:09 PM
Yes, I believe its for Flash 8.....

MichaelxxOA
02-11-2006, 11:30 PM
astgtciv: Thanks, and no problem.

Yes this class is Flash 8 specific due to the use of the ExternalInterface API. If you guys use this can you please post examples so that others can see when and why to use it. Take Care.

_Michael

yker22
02-12-2006, 12:43 AM
Hi Michael, this class looks interesting... I´m trying to run swf after change that import list* line but I get this error:

**Error** C:\unzipped\DoubleClick[1]\DoubleClick.as: Line 13: The class or interface 'ListenerList' could not be loaded.
private var listeners : ListenerList;

Total ActionScript Errors: 1 Reported Errors: 1


Thanks

MichaelxxOA
02-12-2006, 01:38 AM
I apologize, look at the posts a few above this.. they talk about what is wrong.. I didn't change the import statement. Sorry. Take Care.

_Michael

MichaelxxOA
02-12-2006, 04:46 AM
I've been asked some questions on other forums about this class.. here's a quick comment in case any others are wondering..

Cookies aren't a mechanism for storing large amounts of data. They are a way to allow a rather stateless environment to have some sort of memory that is not weighted on the server.

Let's say for an extremely simple example that you have to manage users in your current project. This means that a user has to be able to log into your site and retain that status until a time that you specify. Now in the case of shared objects we could log the user in and store a loggedIn value on the users machine, but let's say that Flash isn't not the only means of viewing this site. Let's say they click on a link that takes them to a non-flash page. In order for them to retain their logged in status you will have to have some way of storing that state in an accessible way. Sharedobjects while I believe are possible to read on the server side require more work. Cookies on the other hand are an easily accessible way of storing data.

This works in the reverse as well. Let's say that you have a site that is for the most part comprised of non-flash pages. This includes your logging in. When a user logs in and clicks on a Flash page there may be content that is accessible to logged in users, how does your flash movie know that the user viewing the swf is of the status logged in? This is where cookies can play a vital role in your project.

Like I said, this isn't a class written to save the world, it's just a tool. There may never be a time that requires you to use this class, and my simple example is probably only scratching the surface of what is possible. I'm simply listing it here so that in the event that someone needs this functionality it is available to them. Thanks for the feedback guys it is truly appreciated.

Take Care.

_Michael

MichaelxxOA
03-01-2006, 07:34 PM
Having to use C# at work I find that there are little things that us AS developers dont' have, this is one of them... it's a simple method for making string insertions.. I put it into a String Utility class so that I may add methods later, who knows. Take Care, and use this however you see fit.

Okay I took the time to throw this into a string utility class... I'm not sure how possible it is going to be to add to this, but hell why not... here's the code listing for the class, and how you'd use it in your fla at the bottom. Enjoy, and take care.

_Michael

StringUtility.as:


// this is a class we will use to transform strings
// it will grow as we see fit.
// for the most part just a method library geared towards
// strings specifically
class StringUtility
{
// inserts values into a string
public static function insertion (original : String, args : String ) : String
{
// some constants.. what are markers tags are...
var MARKER_OPEN : String = "{";
var MARKER_CLOSE : String = "}";
// The string with all the values set...
var new_string : String = "";
// represents our current search position of the character {
var position_1 : Number = null;
// represents our current search position of the character }
var position_2 : Number = null;
// the number that represents the marker (argument) value that we are currently on
var argument : Number = 0;
// the string we are replacing our argument with
var argumentValue : String = "";
while (true)
{
// the position we are searching from...
var search_from : Number;
// if the position has not been set, start from the beginning
if (position_1 == null)
{
search_from = 0;
} else
{
search_from = position_1 + 1;
}
// set position to the next index of the next instance of our MARKER_OPEN
position_1 = original.indexOf (MARKER_OPEN, search_from);
// if there are no more instances of MARKER_OPEN in this string, then break from the loop
if (position_1 == - 1) break;

// where we will begin the slicing of our string at... start at 0
var start : Number = 0;
// where we will end the slicing of our string at... end at position_1
var end : Number = position_1;
// if position_2 has been set, then start is always the character index AFTER position_2
if (position_2 != null)
{
start = position_2 + 1;
}
// add to new_string the contents between this and the last marker
// if this is the first marker then it just adds from the beginning of the string
new_string += original.substring (start, end);

// set position_2 to the index of MARKER_CLOSE after our current MARKER_OPEN
position_2 = original.indexOf (MARKER_CLOSE, position_1);
// parse the argument as an integer.. requires string manipulation to pull the marker
// value out.
argument = parseInt (original.substring (position_1 + 1, position_2));
// pull from the arguments array the value that will replace this marker...
argumentValue = arguments [argument + 1];
// add our argument value, so that our new_string no longer contains a marker, but
// instead the value
new_string += argumentValue;

}
// when we are done, there are no more markers, so just add on the remainder
// of our original string from the last marker on, onto our new_string
new_string += original.substring (original.lastIndexOf (MARKER_CLOSE) + 1, original.length);
// return our string with all the inserted values
return new_string;
}
}



FLA Usage:


var s = StringUtility.insertion("<a href='{0}'>{1}</a>", "http://www.createage.com", "Michael's Site");

// traces... <a href='http://www.createage.com'>Michael's Site</a>
trace(s);

Flash Gordon
03-01-2006, 08:05 PM
Thanks for posting :)

MichaelxxOA
03-01-2006, 08:29 PM
never a problem, ;). Glad you enjoy.

Take Care.
-Michael

MichaelxxOA
03-01-2006, 09:29 PM
If anyone does not understand, the reasons or how to use this, please ask so that I can address that, take care.

_Michael

MichaelxxOA
03-02-2006, 03:34 AM
An updated method:


// this is a class we will use to transform strings
// it will grow as we see fit.
// for the most part just a method library geared towards
// strings specifically
class StringUtility
{

// checks whether or not a string contains a specific series of characters
public static function contains(the_string : String, args : String) : Boolean
{
// how many different strings are we checking for...
var strings : Number = arguments.length-1;

// loop through how many we are checking for, and
for (var i:Number=0; i<strings; i++)
{
if (the_string.indexOf(arguments[i+1]) == -1)
{
// if the string does not contain what we asked for.
return false;
}
}

// if we get this far, then the string did contain everything we asked for...
return true;
}

// inserts values into a string
public static function insertion (original : String, args : String ) : String
{
// some constants.. what are markers tags are...
var MARKER_OPEN : String = "{";
var MARKER_CLOSE : String = "}";
// The string with all the values set...
var new_string : String = "";
// represents our current search position of the character {
var position_1 : Number = null;
// represents our current search position of the character }
var position_2 : Number = null;
// the number that represents the marker (argument) value that we are currently on
var argument : Number = 0;
// the string we are replacing our argument with
var argumentValue : String = "";
while (true)
{
// the position we are searching from...
var search_from : Number;
// if the position has not been set, start from the beginning
if (position_1 == null)
{
search_from = 0;
} else
{
search_from = position_1 + 1;
}
// set position to the next index of the next instance of our MARKER_OPEN
position_1 = original.indexOf (MARKER_OPEN, search_from);
// if there are no more instances of MARKER_OPEN in this string, then break from the loop
if (position_1 == - 1) break;

// where we will begin the slicing of our string at... start at 0
var start : Number = 0;
// where we will end the slicing of our string at... end at position_1
var end : Number = position_1;
// if position_2 has been set, then start is always the character index AFTER position_2
if (position_2 != null)
{
start = position_2 + 1;
}
// add to new_string the contents between this and the last marker
// if this is the first marker then it just adds from the beginning of the string
new_string += original.substring (start, end);

// set position_2 to the index of MARKER_CLOSE after our current MARKER_OPEN
position_2 = original.indexOf (MARKER_CLOSE, position_1);
// parse the argument as an integer.. requires string manipulation to pull the marker
// value out.
argument = parseInt (original.substring (position_1 + 1, position_2));
// pull from the arguments array the value that will replace this marker...
argumentValue = arguments [argument + 1];
// add our argument value, so that our new_string no longer contains a marker, but
// instead the value
new_string += argumentValue;

}
// when we are done, there are no more markers, so just add on the remainder
// of our original string from the last marker on, onto our new_string
new_string += original.substring (original.lastIndexOf (MARKER_CLOSE) + 1, original.length);
// return our string with all the inserted values
return new_string;
}
}

MichaelxxOA
03-05-2006, 01:37 AM
So I know a while ago I gave you guys a MultiKey class for detecting when key combinations have been pressed. I started using that and found that.. it sucked, bad... I spent the last hour putting together a much nicer class for detecting Key Combinations, and here it is...

Save as, KeyDetection.as

/* Created to allow us to listen for key combinations.
*
* @author Michael Avila
* @version 1.0
*/
class KeyDetection
{
// a list of all the key codes that have been pressed
private var keys_pressed : Array;
// a multi-dimensional list of all of our key combinations
private var key_combinations : Array;
// objects listening to this detection
private var listeners : Array;
/* Constructor */
public function KeyDetection ()
{
keys_pressed = new Array ();
key_combinations = new Array ();
listeners = new Array ();
// allow this object to listen for events from the key object
Key.addListener (this);
}
/* Registers an object to listen for events from the KeyDetection class
*
* @param The object that will listen for the events
*/
public function addListener (listener : Object) : Void
{
for (var i : Number = 0; i < listeners.length; i ++)
{
if (listeners [i] == listener) return;
}
listeners.push (listener);
}
/* Unregisters an object that is listening for events from the KeyDetection class
*
* @param The object you wish to remove from the listeners list
*/
public function removeListener (listener : Object) : Void
{
for (var i : Number = 0; i < listeners.length; i ++)
{
if (listeners [i] == listener) listeners.splice (i, 1);
}
}
/* Adds a key combination to listen for
*
* @param The name you are giving this combination. Note that this is how you will identify which combination
* has been pressed.
* ...
* @param The key codes that you are part of this combination. Note that they will need to be pressed in the order
* that you list them in order for the combination to be fire successfully.
*
* @usage <pre>var key_detector = new KeyDetection();
* key_detector.addCombination("undo", Key.CONTROL, 90);
* </pre>
*
*/
public function addCombination (name : String, keyCode1 : Number, keyCode2 : Number) : Void
{
key_combinations.push (arguments);
}
// invokes the onKeyCombination event on all listeners
private function invokeOnKeyCombination (combo_name : String ) : Void
{
for (var i : Number = 0; i < listeners.length; i ++)
{
listeners [i].onKeyCombination (combo_name);
}
}
private function onKeyDown ()
{
var key : Number = Key.getCode ();
cleanKeysPressed ();
if (key != keys_pressed [keys_pressed.length - 1])
{
keys_pressed.push (key);
}
checkCombinations ();
}
private function checkCombinations ()
{
for (var j : Number = 0; j < key_combinations.length; j ++)
{
for (var i : Number = 0; i < keys_pressed.length; i ++)
{
if (keys_pressed [i] == key_combinations [j][i + 1])
{
if (i == key_combinations [j].length - 2)
{
invokeOnKeyCombination (key_combinations [j][0]);
return;
}
} else
{
break;
}
}
}
}
private function cleanKeysPressed ()
{
for (var i : Number = 0; i < keys_pressed.length; i ++)
{
if ( ! Key.isDown (keys_pressed [i]))
{
keys_pressed.splice (i, (keys_pressed.length - i));
}
}
}
}



Here is an example of how you'd use it in your fla...


_root.createTextField("message_txt", 100, 0, 0, 550, 400);

var keyDet = new KeyDetection();
keyDet.addCombination("undo", Key.CONTROL, 90);
keyDet.addCombination("redo", Key.CONTROL, 89);

myObj = new Object();
myObj.onKeyCombination = function(name:String)
{
switch (name)
{
case "undo":
message_txt.text = "Undo Combination Pressed";
break;
case "redo":
message_txt.text = "Redo Combination Pressed";
break;
}
}
keyDet.addListener(myObj);


WARNING: In order for this example to work you have to view it either in a browser or a stand alone swf player, because the Flash IDE takes over the CONTROL key so once it's pressed you don't hear from any other keys.

Anyway this is an extremely easy way to detect key combinations... there's also documentation for this class found here...

www.nowtheworld.com/ASDocs/KeyDetection

This has been bugging me for a while, so I'd like to get some feedback on it, take care guys.

_Michael

Cota
03-05-2006, 01:42 AM
again, another valuable contribution..thank you very much..

MichaelxxOA
03-05-2006, 01:45 AM
;) and again, it's never a problem. Thanks Cota.

_Michael

MichaelxxOA
03-05-2006, 01:48 AM
I should probably mention that you are not tied down to a combination of only two keys, you can have as many keys as you'd like, for instance there's nothing keeping you from putting...


_root.createTextField("message_txt", 100, 0, 0, 550, 400);

var keyDet = new KeyDetection();
keyDet.addCombination("undo", Key.CONTROL, 90);
keyDet.addCombination("redo", Key.CONTROL, 89);

// here we have more than two keys
keyDet.addCombination("save as", Key.CONTROL, Key.SHIFT, 83);

Key.addListener(this);
function onKeyDown()
{
trace(Key.getCode());
}

myObj = new Object();
myObj.onKeyCombination = function(name:String)
{
switch (name)
{
case "undo":
message_txt.text = "Undo Combination Pressed";
break;
case "redo":
message_txt.text = "Redo Combination Pressed";
break;
case "save as":
message_txt.text = "Save As Combination Pressed";
break;
}
}
keyDet.addListener(myObj);


_Michael

Cota
03-05-2006, 01:52 AM
I cant wait til the new system comes out...I am so nominating you for some tutorials and stuff...

MichaelxxOA
03-05-2006, 01:53 AM
Me either, I'm excited, thanks for the support :)... I'd be more than glad to write... a little off topic but, have you ever used this AS2DOC? the full version?

I want to get it but I'm not sure if it's worth it, although it seems that it is.

_Michael

Cota
03-05-2006, 01:58 AM
I personally have never used it, dont know anyone that has either....What other little classes or tid-bits do you have in the works...

MichaelxxOA
03-05-2006, 01:59 AM
I've been messing around with a DrawingUtility class... um... I can post that if you'd like, I have documentation for that as well...

www.nowtheworld.com/ASDocs/DrawingUtility/

I dont' know, I have to make so much stuff everyday for work, let me look through my stuff, and my upcoming projects, I'll get back to you in a minute.. I'll post a new thread for the DrawingUtility...

_Michael

Cota
03-05-2006, 02:01 AM
You make me feel like such a novice...

MichaelxxOA
03-05-2006, 02:04 AM
Another simple class that just makes things alot easier, this was made to replace accessing a movieclips drawing methods directly, and giving methods for drawing common objects quickly...

Saved as, DrawingUtility.as

/*
* @author Michael Avila
* @version 1.0
*
* @description Instead of doing the tedious work of drawing each object, we will use this as a utility, adding
* shapes as we see fit.
*/
class DrawingUtility
{
// the movieclip that we are currently drawing into
private var target : MovieClip;
// the default lineStyle
private var dLineSize : Number = 0;
private var dLineColor : Number = 0x0;
private var dLineAlpha : Number = 100;
// the current line style
private var lineSize : Number;
private var lineColor : Number;
private var lineAlpha : Number;
/*
* @param The movieclip that we will be drawing into
*
*
*/
public function DrawingUtility (target : MovieClip )
{
this.target = target;
resetDefaultStyle ();
}
/******************************************** PUBLIC METHODS ***/
/* Keeping things well formed, we will eliminate the need for access to
* a movieclips drawing methods if a drawing utility exists.. instead, you
* will utilize these methods.
*/
/* Draws a line from where the current location of the pen to the location you specify.
* @param Where on the x axis to draw to
* ...
* @param Where on the y axis to draw to
*
* @return n/a
*
*/
public function lineTo (x : Number, y : Number) : Void
{
target.lineStyle (lineSize, lineColor, lineAlpha);
target.lineTo (x, y);
}
/* Moves the pen from the current location to the location you specify, without drawing a line.
* @param Where on the x axis to move to
* ...
* @param Where on the y axis to move to
*
* @return n/a
*
*/
public function moveTo (x : Number, y : Number) : Void
{
target.lineStyle (lineSize, lineColor, lineAlpha);
target.moveTo (x, y);
}
/* Curves to the point that you specify
* @param Where on the x axis our curved line will end
* ...
* @param Where on the y axis our curved line will end
* ...
* @param Where on the x axis our curve will bend to
* ...
* @param Where on the y axis our curve will bend to
*
* @return n/a
*/
public function curveTo (controlX : Number, controlY : Number, anchorX : Number, anchorY : Number) : Void
{
target.lineStyle (lineSize, lineColor, lineAlpha);
target.curveTo (controlX, controlY, anchorX, anchorY);
}
/* Removes the user/default linestyle for a single draw.
*
* @return n/a
*
* Sets our linestyle to none, useful since there will always be a default style unless
* changed explicitly.
*/
public function noLineStyle () : Void
{
lineSize = lineColor = lineAlpha = null;
}
/* Sets the linestyle
* @description Sets the style of our line
* @param The size of our line
* ...
* @param The color of our line
* ...
* @param The transparency of our line
*
* @return n/a
*
*/
public function lineStyle (size : Number, color : Number, alpha : Number) : Void
{
lineSize = size;
lineColor = color;
lineAlpha = alpha;
}
/* Begins a fill in your movieclip
* @description Begins our fill
* @param The color of our fill
* ...
* @param The transparency of our fill
*
* @return n/a
*
*/
public function beginFill (rgb : Number, alpha : Number) : Void
{
target.beginFill (rgb, alpha);
}
/* Ends the fill in your movieclip
* @description Ends our fill.
*/
public function endFill () : Void
{
target.endFill ();
}
/* Clears all drawings in the target
*/
public function clear () : Void
{
target.clear ();
}
/* Draws an Ellipse into our target movieclip
* @param The radius of our ellipse along the x axis
* ...
* @param The radius of our ellipse along the y axis
* ...
* @param Where the center of our ellipse lies on the x axis
* ...
* @param Where the center of our ellipse lies on the y axis
*
* @return n/a
*/
public function drawEllipse (radiusX : Number, radiusY : Number, centerX : Number, centerY : Number) : Void
{
var points : Number = 360 / 56;
target.lineStyle (lineSize, lineColor, lineAlpha);
var firstX : Number = centerX + Math.cos (.01) * radiusX;
var firstY : Number = centerY + Math.sin (.01) * radiusY;
target.moveTo (firstX, firstY);
for (var i : Number = 0; i < points; i +=.01)
{
var x : Number = centerX + Math.cos (i) * radiusX;
var y : Number = centerY + Math.sin (i) * radiusY;
target.lineTo (x, y);
}
resetDefaultStyle ();
}
/* Draws a Circle into our target movieclip
*
* @param The radius of our circle
* ...
* @param Where the center of our circle lies on the x axis
* ...
* @param Where the center of our circle lies on the y axis
*
* @return n/a
*
*/
public function drawCircle(radius:Number, centerX:Number, centerY:Number) : Void
{
// all this method is is an alias to the drawEllipse.. so we just manually pass in our info ;)
drawEllipse(radius, radius, centerX, centerY);
}
/* Draws a line into our target movieclip
* @param Where our line begins on the x axis
* ...
* @param Where our line begins on the y axis
* ...
* @param Where our line ends on the x axis
* ...
* @param Where our line ends on the y axis
*
* @return n/a
*/
public function drawLine (startX : Number, startY : Number, endX : Number, endY : Number) : Void
{
target.lineStyle (lineSize, lineColor, lineAlpha);
target.moveTo (startX, startY);
target.lineTo (endX, endY);
resetDefaultStyle ();
}
/* Draws a rectangle into our target movieclip
* @param Where the top left corner of our rectangle lies on the x axis
* ...
* @param Where the top left corner of our rectangle lies on the y axis
* ...
* @param Where the bottom right corner of our rectangle lies on the x axis
* ...
* @param Where the bottom right corner of our rectangle lies on the y axis
*
* @return n/a
*/
public function drawRectangle (startX : Number, startY : Number, endX : Number, endY : Number) : Void
{
target.lineStyle (lineSize, lineColor, lineAlpha);
target.moveTo (startX, startY);
target.lineTo (startX, endY);
target.lineTo (endX, endY);
target.lineTo (endX, startY);
target.lineTo (startX, startY);
resetDefaultStyle ();
}
/* This will draw a polygon based on the number of sides and radius you provide
*
* @param The number of sides this polygon contains
* ...
* @param The distance from the center of the polygon to it's furthest point
* ...
* @param Where the center of our polygon lies on the x axis
* ...
* @param Where the center of our polygon lies on the y axis
*
* @return n/a
*/
public function drawPolygon (sides : Number, radius : Number, centerX : Number, centerY : Number) : Void
{
// error handling..
if (sides < 3)
{
trace ("ERROR: Invalid Parameter Value \n\tThe Method: drawPolygon requires that the sides parameter be greater than or equal to two.");
return;
}
// line styles..
target.lineStyle (lineSize, lineColor, lineAlpha);
var angle : Number = 360 / sides;
var current_side : Number = 0;
while (current_side <= sides)
{
var a = angle * current_side / 180 * Math.PI;
var x : Number = radius * Math.sin (a);
var y : Number = radius * Math.cos (a);
if ( ! current_side)
{
// if this is the first side, we need to move out to the correct point
target.moveTo (x, y);
}
else
{
// if we are already started, go ahead and draw from point to point.
target.lineTo (x, y);
}
current_side ++;
}
// reposition the target if coordinates were given
if (centerX != null && centerY != null)
{
target._x = centerX;
target._y = centerY;
}
resetDefaultStyle ();
}

/* By far the most complicated of our drawing utilities, this will
* draw a star based on the number of points and radius you provide
* @param The number of points this star contains
* ...
* @param The distance from the center of the star to it's inner points
* ...
* @param The distance from the center of the star to it's outer points
* ...
* @param Where the center of our star lies on the x axis
* ...
* @param Where the center of our star lies on the y axis
*
* @return n/a
*/
public function drawStar (points : Number, innerRadius : Number, outerRadius : Number, centerX : Number, centerY : Number) : Void
{
var sides = points * 2;

// line styles..
target.lineStyle(lineSize, lineColor, lineAlpha);
var angle : Number = 360 / sides;
var current_side : Number = 0;

while (current_side <= sides)
{
var innerAngle = angle * current_side / 180 * Math.PI;
var outerAngle = angle * (current_side + 1) / 180 * Math.PI;

var x : Number = innerRadius * Math.sin (innerAngle);
var y : Number = innerRadius * Math.cos (innerAngle);
var xOuter : Number = outerRadius * Math.sin (outerAngle);
var yOuter : Number = outerRadius * Math.cos (outerAngle);

if (current_side == 0)
{
// if this is the first side, we need to move out to the correct point
target.moveTo (x, y);
target.moveTo (xOuter, yOuter);
} else
{
// if we are already started, go ahead and draw from point to point.
target.lineTo (x, y);
target.lineTo (xOuter, yOuter);
}
current_side += 2;
}
// reposition the target if coordinates were given
if (centerX != null && centerY != null)
{
target._x = centerX;
target._y = centerY;
}
resetDefaultStyle ();
}
/******************************************** PRIVATE METHODS ***/
/* Resets the current line style to the default */
private function resetDefaultStyle () : Void
{
lineSize = dLineSize;
lineColor = dLineColor;
lineAlpha = dLineAlpha
}
}

MichaelxxOA
03-05-2006, 02:05 AM
Sorry to have to post twice, but it cut me off...

An example of how you'd use it in an fla...


var drawer = new DrawingUtility(_root);

drawer.beginFill(Math.random() * 0xFFFFFF, 100);
drawer.lineStyle(1, Math.random() * 0xFFFFFF, 100);
drawer.drawStar(5, 50, 150, Stage.width/2, Stage.height/2);
drawer.endFill();


And documentation can be found here..

www.nowtheworld.com/ASDocs/DrawingUtility

_Michael

MichaelxxOA
03-05-2006, 02:06 AM
Yeah right, I'm sure you'd work me ;), I'm just glad we are part of such an open source community, there's truly no other environment in computing like the Flash Community.

_Michael

billingsgate
03-05-2006, 02:57 AM
Thanks. I've just been learning the fine points of the movie clip drawing method. This class looks like an elegant way to implement it much more easily.

MichaelxxOA
03-05-2006, 03:04 AM
That's what I'm thinking, for people that are not familiar with flash, drawing with a drawing utility is probably going to make much more sense then just drawing into whatever, plus the ability to create common shapes with no effort has saved me so much time, even if it's just the testing of an idea.

_Michael

drumrby
03-05-2006, 04:58 AM
Hey Michael,
Great job man, I cant wait to find a way to use it in my next project, lol. You never cease to amaze me.

drumrby
03-05-2006, 05:02 AM
Again, another masterpiece from the master. Dude, you are on fire with you new stuff. :)

MichaelxxOA
03-05-2006, 06:09 AM
An updated method... replace() will replace all occurances of a series of characters with the string of characters you provide...


// this is a class we will use to transform strings
// it will grow as we see fit.
// for the most part just a method library geared towards
// strings specifically

/*
*
*@author Michael Avila
*@version 1.3
*@description This is a class for handling strings.
*/
class StringUtility
{

/* Replaces all occurances of one series of characters with another series of characters
*
* @param The string you are invoking the replace on.
* ...
* @param The series of characters which you plan on replacing
* ...
* @param The series of characters you are replacing with.
*
* @return The string with our values replaced
*
* @usage <pre>StringUtility.replace("Hello World", "World", "Michael");</pre>
*/
public static function replace(original : String, string1 : String, string2 : String) : String
{
var return_string : String = "";

var start_position : Number = 0;
var end_position : Number = 0;

while (true)
{
start_position = original.indexOf(string1, end_position);

if (start_position == -1) break;

return_string += original.substring(end_position, start_position);
return_string += string2;

end_position = start_position + string1.length;
}

return_string += original.substring(end_position, original.length);

return return_string;
}

/* Returns whether or not your series of characters is contained within this string
* @param The string you are going to be looking in
* ...
* @param The strings of characters that you will be looking for.
*
* @return Returns true if all the specified arguments are contained in the string
* and false if not.
*
* @usage <pre>StringUtility.contains("this is the search string", "this", "search");</pre>
*/
public static function contains(the_string : String, args : String) : Boolean
{
// how many different strings are we checking for...
var strings : Number = arguments.length-1;

// loop through how many we are checking for, and
for (var i:Number=0; i<strings; i++)
{
if (the_string.indexOf(arguments[i+1]) == -1)
{
// if the string does not contain what we asked for.
return false;
}
}

// if we get this far, then the string did contain everything we asked for...
return true;
}

/* Inserts values into a string.
* @param The string you are going to be inserting values into
* ...
* @param The values that you will be adding into the string
*
* @return Returns the string with all of your values inserted
*
* @usage <pre>StringUtility.insertion("Hello: {0}, this is visit number {1}.", "Michael", "20");</pre>
*
*/
public static function insertion (original : String, args : String ) : String
{
// some constants.. what are markers tags are...
var MARKER_OPEN : String = "{";
var MARKER_CLOSE : String = "}";
// The string with all the values set...
var new_string : String = "";
// represents our current search position of the character {
var position_1 : Number = null;
// represents our current search position of the character }
var position_2 : Number = null;
// the number that represents the marker (argument) value that we are currently on
var argument : Number = 0;
// the string we are replacing our argument with
var argumentValue : String = "";
while (true)
{
// the position we are searching from...
var search_from : Number;
// if the position has not been set, start from the beginning
if (position_1 == null)
{
search_from = 0;
} else
{
search_from = position_1 + 1;
}
// set position to the next index of the next instance of our MARKER_OPEN
position_1 = original.indexOf (MARKER_OPEN, search_from);
// if there are no more instances of MARKER_OPEN in this string, then break from the loop
if (position_1 == - 1) break;

// where we will begin the slicing of our string at... start at 0
var start : Number = 0;
// where we will end the slicing of our string at... end at position_1
var end : Number = position_1;
// if position_2 has been set, then start is always the character index AFTER position_2
if (position_2 != null)
{
start = position_2 + 1;
}
// add to new_string the contents between this and the last marker
// if this is the first marker then it just adds from the beginning of the string
new_string += original.substring (start, end);

// set position_2 to the index of MARKER_CLOSE after our current MARKER_OPEN
position_2 = original.indexOf (MARKER_CLOSE, position_1);
// parse the argument as an integer.. requires string manipulation to pull the marker
// value out.
argument = parseInt (original.substring (position_1 + 1, position_2));
// pull from the arguments array the value that will replace this marker...
argumentValue = arguments [argument + 1];
// add our argument value, so that our new_string no longer contains a marker, but
// instead the value
new_string += argumentValue;

}
// when we are done, there are no more markers, so just add on the remainder
// of our original string from the last marker on, onto our new_string
new_string += original.substring (original.lastIndexOf (MARKER_CLOSE) + 1, original.length);
// return our string with all the inserted values
return new_string;
}
}


Documentation:
www.nowtheworld.com/asdocs/stringutility

Enjoy. Take Care.

_Michael

MichaelxxOA
03-05-2006, 06:46 AM
Going through some old stuff again and stumbled on this... if you guys can use it for whatever... I'm having a very bored if you can't tell...

This class is extremely simple to use, you just create a new instance of it passing into the constructor either the instance name of the movieclip that you would like to follow the mouse, or the identifier name that you gave the symbol in the library... then you call activate() to make it your cursor and deactivate() to make it not your cursor...

Saved as, CustomCursor.as

/*
* @author Michael Avila
* @version 1.0
*/

class CustomCursor
{
// our cursor movieclip
private var cursor : MovieClip;
private var event_cursor : MovieClip;

/* Our CustomCursor Constructor
*
* @param Either the instance name of the movieclip that you are using as a custom cursor or
* the identifier name that you gave it in the Library.
*
* @usage <pre>var cursor = new CustomCursor(my_cursor);// movieclip
* // or
* var cursor = new CustomCursor("my_cursor");// from library
* </pre>
*/
public function CustomCursor( cursor : Object )
{
switch (typeof cursor)
{
case "string":
this.cursor = _root.attachMovie(cursor.toString(), cursor.toString(), _root.getNextHighestDepth());
break;
case "movieclip":
this.cursor = MovieClip(cursor);
break;
default:
trace("You must supply either an identifier name or an instance name");
break;
}

event_cursor = _root.createEmptyMovieClip("alsdkfj", 13000);
event_cursor.onMouseMove = function() { updateAfterEvent() };
}

/* Activates our cursor, activation involves hiding the Mouse and telling our CustomCursor to follow the mouse position. */
public function activate()
{
Mouse.hide();
Mouse.addListener(this);
}
/* Deactivates our cursor, deactivation involves showing the mouse and telling our custom cursor to stop following the mouse positions */
public function deactivate()
{
Mouse.show();
Mouse.removeListener(this);
}
// gets called when the mouse moves
public function onMouseMove():Void
{
cursor._x = _root._xmouse;
cursor._y = _root._ymouse;
}
}


Code as it would appear in the .fla


var cursor = new CustomCursor(my_cursor);// uses mc that is already on stage
// or
var cursor1 = new CustomCursor("my_cursor");// pulls from library
cursor.activate();


Take Care guys.
_michael

MichaelxxOA
03-05-2006, 08:52 PM
I packaged up a version of this class since I think that people will be using it alot, if you have the extension manager download it from here..


http://nowtheworld.com/repository/Flash/KeyDetector.zip

This mxp includes the Class file as well as all the Code Hinting and Syntax Highlighting.

_Michael

MichaelxxOA
03-06-2006, 12:22 AM
This is another class that I have to use for work, never really thought about posting it, but it's another extremely boring day for me...

This class is really basic, and is not meant to be used with setInterval or anything, it's more of a StopWatch.. you can start, stop and reset. When you ask for the time, you ask for it in a specific format. What you do with the timer is your call, this isn't made for anything specifically...

/* A simple timer class.. does exactly as you would expect a stop watch to do, nothing more, nothing less.
*
* @author Michael Avila
* @version 1.0
*/
class XTimer
{
private var mseconds:Number = 0; // the total milliseconds
private var isRunning:Boolean = false; // is the timer running
private var last_check:Number = 0; // last timer value

/* The format for Milliseconds */
public static var MILLISECONDS:Number = 1;
/* The format for Seconds */
public static var SECONDS:Number;
/* The format for Minutes */
public static var MINUTES:Number;
/* The format for Hours */
public static var HOURS:Number;


public function XTimer()
{
SECONDS = XTimer.MILLISECONDS * 1000;
MINUTES = XTimer.SECONDS * 60;
HOURS = XTimer.MINUTES * 60;
}

/* Starts the timer */
public function start():Void
{
isRunning = true;
}
/* Stops the timer */
public function stop():Void
{
isRunning = false;
last_check = getTimer();
}
/* Resets the timer */
public function reset():Void
{
mseconds = 0;
last_check = 0;
}

/* Returns the time, in the format you specify.
*
* @param The format that you wish the time to be returned in, pass in one of XTimer's properties for formats.
*
* @usage <pre>myTimer.getTime(XTimer.SECONDS);</pre>
*/
public function getTime( time_format:Number ):Number
{
updateTime();
return Math.floor(mseconds/time_format);
}

// updates the timer
private function updateTime():Void
{
if (isRunning)
{
mseconds += getTimer() - last_check;
last_check = getTimer()
}
}
}


Code usage in the fla..


Key.addListener(this);

var stop_watch = new XTimer();
stop_watch.start();

function showTime()
{
trace("Milliseconds: " + stop_watch.getTime(XTimer.MILLISECONDS));
trace("Seconds: " + stop_watch.getTime(XTimer.SECONDS));
trace("Minutes: " + stop_watch.getTime(XTimer.MINUTES));
}

function onKeyDown()
{
if (Key.getCode() == Key.SPACE)
{
showTime();
}
}


Enjoy, I'm curious to see what people end up using this for. Take Care.

_Michael

MichaelxxOA
03-07-2006, 05:42 AM
There is now a tutorial up for this class, it can be found here:

http://www.actionscript.org/dev/articles/192/1/Detecting-Key-Combinations

Take Care.

_Michael

MichaelxxOA
03-07-2006, 12:03 PM
Another one of those utilities I have laying around, that I'm sure someone here can make good use of.

Let's say your developing an application and you want to be able to configure specifics of this application without editing code... well if you create a config file that is stored on the server that looks like the following...

Saved as, AppConfig.config
<?xml version="1.0"?>

<configuration>
<appSettings>
<!-- If you'd like to add a new app setting you simply have to add a new <setting> node..
always give your setting a name that is intuitive, because this is how you will access it -->
<setting name="image_dir" value="images/" />
</appSettings>
<userSettings>
<!-- If you'd like to add a new user setting you simply have to add a new <setting> node..
always give your setting a name that is intuitive, because this is how you will access it -->
<setting name="allowAll" value="true" />
</userSettings>
</configuration>


And you save the following class in your default class path as, AppConfigReader.as



class AppConfigReader extends XML
{
// ignore all white space in the xml file
private var ignoreWhite:Boolean = true;
// all listeners listeneing to this object
private var listeners:Array;

public function AppConfigReader()
{
listeners = new Array();
}

/* Returns the value of the Application Setting you specify */
public function getAppSetting(name:String) : String
{
var startNode:XMLNode = this.firstChild.firstChild;
for (var i:Number=0; i<startNode.childNodes.length; i++)
{
if (startNode.childNodes[i].attributes.name == name)
{
return startNode.childNodes[i].attributes.value;
}
}

return undefined;
}

/* Returns the value of the Application Setting you specify */
public function getUserSetting(name:String) : String
{
var startNode:XMLNode = this.firstChild.childNodes[1];
for (var i:Number=0; i<startNode.childNodes.length; i++)
{
if (startNode.childNodes[i].attributes.name == name)
{
return startNode.childNodes[i].attributes.value;
}
}

return undefined;
}

/* Register a listener to listen for onLoad events from this object */
public function addListener(listener:Object):Boolean
{
for (var i:Number = 0; i<listeners.length; i++)
{
if (listeners[i] == listener) return false;
}

listeners.push(listener);
return true;
}
/* Unregisters a listener from this object */
public function removeListener(listener:Object):Boolean
{
for (var i:Number = 0; i<listeners.length; i++)
{
if (listeners[i] == listener)
{
listeners.splice(i, 1);
return true;
}
}

return false;
}

private function invokeOnLoad(success : Boolean) : Void
{
for (var i:Number = 0; i<listeners.length; i++)
{
listeners[i].onLoad(success);
}
}
private function onLoad(success:Boolean):Void
{
invokeOnLoad(success);
}
}


You can then access these values in the fla like this..

Fla Code:


var app_configs_rdr = new AppConfigReader();

app_configs_rdr.load("AppConfig.config");

var my_obj = new Object();

my_obj.onLoad = function(success:Boolean):Void
{
trace(app_configs_rdr.getAppSetting("image_dir"));
trace(app_configs_rdr.getUserSetting("allowAll"));
}

app_configs_rdr.addListener(my_obj);


If something doesn't make sense, go ahead and ask and I will explain. Take Carre.

_Michael

Xeef
03-07-2006, 02:28 PM
you coud ask jesse to make a thread/directory whit usefull "tools" (or what ever title) whit stoff like this

including your keycombination and drawing tool ....

woud save a lot of work if we coud just point to this if the question is coming up agein



good work keap it coming ;)

MichaelxxOA
03-07-2006, 05:47 PM
Yeah, that's actually not a bad idea at all, I'll do that. Thanks Xeef, Take Care.

_Michal

Cota
03-07-2006, 06:45 PM
Yet another little gem from Michael....awesome stuff...

MichaelxxOA
03-07-2006, 06:51 PM
Hey Cota, I was thinking about what Xeef said, and it's not a bad idea. I might be good to have a forum for Utilities, and maybe a sticky for requesting utilities?

Take Care.

_Michael

Cota
03-07-2006, 06:53 PM
I can merge them all into one thread and make it a sticky....

MichaelxxOA
03-07-2006, 06:56 PM
That would work as well. Take Care.

_Michael

Cota
03-07-2006, 07:05 PM
Its alittle messy...but done...

MichaelxxOA
03-07-2006, 07:09 PM
Wow, thanks... very interesting ;), I forgot about some of this already. :(

_Michael

Xeef
03-07-2006, 08:19 PM
I can merge them all into one thread and make it a sticky....


puh :p

as i was saw this long long thread whit this title i was scaring i have missed this
and woud look stupid to MichaelxxOA as i just was write

you coud ask jesse to make a thread/directory whit usefull "tools ...


then i realized this post is here in this thread
so confusion was complit

stop confusing me Cota !


Its alittle messy...but done...

whit this out of topic post even more

will end up geting to big to find useful info

mean if there is a question relating the tool and 20 post later an other one, and 30 post later one more
you need to go truh 100 of sides to find the maching ancer


hi jesse

i think / woud sugest we need and extra topic for tools maked by As.Org members

Tools By Members
----------------- Tools
// just members whit special privileg can post
//one tool one thread
//per tool 3 post (managed by the author)
//1. the tool (as code)
//2. smale description (how to initialize 1-2 examples of use)
//3. FAQ section (whit the most comune questions from "Tools Related Question")
----------------- Tools Related Question
//post questions relating tools


http://www.actionscript.org/forums/newreply.php3?do=newreply&p=460585

^ out to jesse

MichaelxxOA
03-07-2006, 08:27 PM
haha,

come on xeef you really think I'd think you were stupid ;), not a chance!

anyway yeah it's a little confusing but it will work for now I suppose. We just need a way to clean things up. Cota is a champ though, and is doing what he can, much thanks to him as always.

But you're right it will get confusing looking through hundreds of posts for an answer.


_Michael

Cota
03-07-2006, 08:38 PM
Dont worry Xeef...I'll straighten this mess out...just give me some time...

Edit -

Is that better...? I added a linked list to the idividual post....

Jesse
03-07-2006, 10:54 PM
Xeef has suggested to me via PM that we create a new forum for this. I think Xeef, Cota and Michael are all in the CMS now... what do you think about simply having an Article Category for posts like this? I favour using the CMS over the Forums but am open to discussions of benefits of each approach. The CMS would arguably keep everything in one place a little better than threads on the forums.

Xeef
03-07-2006, 11:16 PM
Hmmmm hope i don't sound stupid

but what in hell is CMS (BTW i am not in :p at least i don't know from that i woud by in :p)


The CMS would arguably keep everything in one place a little better than threads on the forums.

that's why i woud sugest to have a topic where just proven people can post "NEW tools"
so in this thread there shoud by just posts from tools
one tool one post

woud by prety clean even if there are 100 tools you easily can flip truh it

Cota
03-07-2006, 11:23 PM
The new CMS system would be best for things of this nature..because it will offer a very easy and clean way of keeping things organized...plus he it will allow authors to update their articles instead of posting new posts or threads to update....I made this a sticky, but I kind of made a mess of it..but at least its there...

Jesse
03-07-2006, 11:49 PM
Xeef - sorry mate, I'm on v little sleep recently (been sttaying up late working on the site and doing long days at work).

We've been setting up a Content Management System (CMS) to run all the articles through. It enables authors to write and edit articles without us having to get in the way. So it basically makes the tuotrials section automated. Plus there are heaps of other benefits. If you'd like to contribute drop me an email mate. It's still in beta which is why you haven't heard about it yet.

MichaelxxOA
03-08-2006, 12:57 AM
I say that you give the Source category a go, we'll see how it works out. What I plan on doing is writing articles on how to use the utilities I create, which I already have one done... Having a source category that people can flip thru and find tools quickly is not a bad idea at all, we can then just post the article on how to use the tool at the bottom of the source post. Take Care.

_Michael

Jesse
03-08-2006, 04:53 AM
Sounds good.

Thanks for editing out the URL Michael. To those who got email notifications which included the CMS URL, please don't share it around just yet. It's not ready for public consumption and we certainly want Google's spiders getting into it just yet.

MichaelxxOA
03-08-2006, 07:10 AM
Fun Fun Fun... yet another utility class for your guys' using pleasure.

Saved as, IdleUserWatcher.as


class IdleUserWatcher
{
// is the user active?
private var __isActive : Boolean = false;
// the id for the interval
private var intervalID : Number;
// how long to wait before calling is idle... default is 10 seconds
private var idleTime : Number = 1000;
// a list of all objects listening
private var listeners : Array;
// readonly property for isActive
public function get isActive () : Boolean
{
return __isActive;
}

public function IdleUserWatcher ( idleTime:Number )
{
if (idleTime != undefined)
{
this.idleTime = idleTime;
}

Mouse.addListener (this);
Key.addListener (this);
listeners = new Array();

}
/* Adds a listener to the listeners list */
public function addListener(listener:Object) : Boolean
{
for (var i:Number=0; i<listeners.length; i++)
{
if (listeners[i] == listener) return false;
}
listeners.push(listener);
return true;
}
/* Removes a listener from the listener list */
public function removeListener(listener:Object) : Boolean
{
for (var i:Number=0; i<listeners.length; i++)
{
if (listeners[i] == listener)
{
listeners.splice(i, 1);
return true;
}
}
return false;
}

/* Events */
private function onKeyDown () : Void
{
setIdleInterval();
}
private function onMouseMove () : Void
{
setIdleInterval();
}

/* Private Methods */
private function setIdleInterval()
{
this.__isActive = true;
clearInterval (this.intervalID);
this.intervalID = setInterval (this, "broadcastIdle", this.idleTime, this);
}
private function broadcastIdle(watcher:IdleUserWatcher) :Void
{
watcher.__isActive = false;
for (var i:Number=0; i<listeners.length; i++)
{
listeners[i].onUserIdle();
}
clearInterval(watcher.intervalID);
}
}



This is an EXTREMELY simple class to use, here is what the code looks like to use it in an fla.


// here you simply tell the object how long to wait for the user
// before deciding he/she is inactive
var idleWatcher = new IdleUserWatcher(1000);

// then we register an object to listen for the onUserIdle() event from
// our IdleUserWatcher object
idleWatcher.addListener(_root);

// IdleUserWatcher has one property, it returns whether or not the user is active
trace(idleWatcher.isActive);

function onUserIdle()
{
trace("BUZZ!!! COME BACK!!");
}


Have fun with this.. I've officially decided that every site I do will now have a screensaver! WOOT!
_Michael

Bowie
03-09-2006, 06:48 PM
I'm not too familiar with using classes, or even know much about how they work I was playing around with the DoubleClick.as class, and I was having problems with the killInterval() interval ID not being cleared. this may have had something to do with the fact that I was instantiating the double click class from deep within my movie?

anyhow I changed:

intID = setInterval(killInterval, this.DELAY);

to

intID = setInterval(this, "killInterval", this.DELAY); and it now works fine from anywhere in my fla file.

there probably is a way to achieve this without modifying the class..

anyway, thank you MichealxxOA.

MichaelxxOA
03-09-2006, 07:27 PM
The DoubleClick class has quite a few things that will make it better, I just have not had any projects that necessitate me modifying it. I appreciate you taking the time to modify and post, that's what it is going to make the utilities become better and better. Take Care, and thanks again Bowie ;).

_Michael

icemart525
03-10-2006, 01:47 AM
Another simple class that just makes things alot easier, this was made to replace accessing a movieclips drawing methods directly, and giving methods for drawing common objects quickly...

Saved as, DrawingUtility.as

/*
* @author Michael Avila
* @version 1.0
*
* @description Instead of doing the tedious work of drawing each object, we will use this as a utility, adding
* shapes as we see fit.
*/
class DrawingUtility
{
}


how can i use this in my .fla? thanks..

MichaelxxOA
03-10-2006, 01:52 AM
You would copy all of that code and paste it into a text file and save it as... DrawingUtility.as, you would then need to put it in your default class path... if you have yet to create your own default class path, you can loook into that, or you can just put this in the same directory as the .fla that will be using it is located.

Then in your fla you would have something like this...


// remember to pass the movieclip you want to draw into here..
var drawer = new DrawingUtility(_root);

// you then invoke all the normal drawing methods on the drawer object...
// and you can also invoke the shape methods...
drawer.lineStyle(0, 0xFF0000, 100);
drawer.beginFill(0xFFFF00, 100);

// call the shape method.
drawer.drawPolygon(6, 100, Stage.width/2, Stage.height/2);

drawer.endFill();


Take Care.

_Michael

icemart525
03-10-2006, 02:03 AM
sorry to bother you but i don't know how to put e default class path...:(
will just pasting DrawingUtility.as in the same directory do it?

and 1 more thing
// remember to pass the movieclip you want to draw into here..
how can i pass the movieclip? :confused:

i'm very excited to use your class and yet i can't follow simple instructions.

MichaelxxOA
03-10-2006, 02:09 AM
Okay Creating a ClassPath.... We'll get you through this :) I promise...

1. Create a folder on your computer somewhere and call it AS 2.0 Classes

2. Open Flash and press CTRL + U, this will open a preferences window.

3. In the Category section on the left select ActionScript.

4. At the bottom where it says.. Language: and then Actionscript 2.0 Settings in a button. Click the button.

5. Now Click on the + sign... when you do this it will add a field to that list

6. With the new field selected, click the Crosshair button ( + ) .. if you hover over it says "Browse to path"... when you do this it will pop up a window where you can look through your files...

7. Look through your folders... locate the AS 2.0 Classes folder you created a moment ago, and select it. Then press OK

8. After pressing okay you'll see that your empty field now has a path to that directory you made... Select this field, and press the UP ARROW so that, your new field is between the... ./ and $(LocalData)/Classes.

Tell me if you have problems doing this.

Take Care.

_Michael

icemart525
03-10-2006, 02:31 AM
ok here's how it looked:

$(LocalData)/Classes // 1st row
. // 2nd row
C:\AS 2.0 Classes // 3rd row

did i get it? what's next? how about the movieclip thing?

MichaelxxOA
03-10-2006, 02:32 AM
alright.. adjust it so that it's like this...

1st row = 3rd row
2nd row = 1st row
3rd row = 2nd row

And then tell me when you're done ;).

icemart525
03-10-2006, 02:37 AM
done.

. // 1st row
C:\AS 2.0 Classes // 2nd row
$(LocalData)/Classes // 3rd row

MichaelxxOA
03-10-2006, 02:45 AM
now create a new actionscript file called DrawingUtiltiy.as, and save it in the directory you created... then copy the DrawingUtility.as code and paste it into your DrawingUtility.as file.... once you have done that, start a new fla and open the actions panel and put..

var drawer = new DrawingUtility(_root);

Tell me if it errors out or anything.

icemart525
03-10-2006, 02:50 AM
ok, no errors,

MichaelxxOA
03-10-2006, 03:04 AM
Okay... make this your actions....


var drawer = new DrawingUtility(_root);

drawer.drawPolygon(6, 100, Stage.width/2, Stage.height/2);


Tell me what happens.

Take care.

icemart525
03-10-2006, 03:06 AM
hmm nothing happened.

MichaelxxOA
03-10-2006, 10:01 AM
New class added... well actually it's a small architecture.. posted on first page.

Take Care.

_Michael

mmm..pi..3.14..
03-10-2006, 10:34 PM
If you feel like it, add the following. It just allows you to do regular expressions in flash (but only when the swf is running in a browser, won't work if doing Control >> Test Movie)


import flash.external.ExternalInterface;
String.prototype.Match = function(PatternStr, ignore_case):String {
return String(ExternalInterface.call("function doRegEx() {var re = new RegExp(\""+PatternStr+"\", \""+(ignore_case ? "i" : "")+"g\");var hasMatch = re.exec(\""+this+"\");if (hasMatch != null) {return hasMatch[0];} else {return false;}}"));
};
String.prototype.Matches = function(PatternStr, ignore_case):Array {
var Results:XML = new XML(ExternalInterface.call("function doRegEx() {var re = new RegExp(\""+PatternStr+"\", \""+(ignore_case ? "i" : "")+"g\");var SearchStr = \""+this+"\";var hasMatch = SearchStr.match(re);if (hasMatch != null) {var xml = \"<ARRAY>\";for(var i=0; i<hasMatch.length; i++){xml += \"<Item><![CDATA[\" + hasMatch[i] + \"]]></Item>\";}xml += \"</ARRAY>\";return xml;} else {return false;}}").toString());
var Output:Array = new Array();
for (i=0; i<Results.firstChild.childNodes.length; i++) {
Output.push(Results.firstChild.childNodes[i].firstChild);
}
return Output;
};
String.prototype.Replace = function(PatternStr, ReplaceStr, ignore_case):String {
return String(ExternalInterface.call("function doRegEx() {var re = new RegExp(\""+PatternStr+"\", \""+(ignore_case ? "i" : "")+"g\");var SearchStr = \""+this+"\";var replaced = SearchStr.replace(re, \""+ReplaceStr+"\");if(replaced != null){return replaced;}return false;}"));
};


************************************************** *******

Match(pattern:String, caseinsensitive:Boolean) : String

Parameters


pattern:String - The Regular Expression pattern to use to match the search string
caseinsensitive:Boolean [optional] - A optional Boolean value to do a case insensitive match. If you omit this parameter, false is used as the default


Returns


If a match is found, the function will return the first match as a string, if you want to find all matches, use the string function Matches
If a match is not found, the function returns the boolean value false.


************************************************** *******

Matches(pattern:String, caseinsensitive:Boolean) : Array

Parameters


pattern:String - The Regular Expression pattern to use to match the search string
caseinsensitive:Boolean [optional] - A optional Boolean value to do a case insensitive match. If you omit this parameter, false is used as the default


Returns


If any matches are found, the function will return an array of all matches that were found
If a match is not found, the function returns the boolean value false.


************************************************** *******

Replace(pattern:String, replacement:String, caseinsensitive:Boolean) : String

Parameters


pattern:String - The Regular Expression pattern to use to match the search string
replacement:String - Any string to replace the regular expression pattern matches, if any
caseinsensitive:Boolean [optional] - A optional Boolean value to do a case insensitive match. If you omit this parameter, false is used as the default


Returns


The String that was inputted with any regular expression matches replaced with the replacement string replacement


************************************************** *******

If you want an example of how to use it, try this:


var TestString = "I like to browse ActionScript.org in my free time";
trace(TestString.Replace("[A-Za-z0-9.]+(org|net|com|gov)", "PHP.net"));// outputs: I like to browse PHP.net in my free time

MichaelxxOA
03-10-2006, 10:43 PM
mmm..pi..3.14.. Nice.. there's also a really good Regular Expression class which can be found here..

http://www.jurjans.lv/flash/RegExp.html (http://www.jurjans.lv/flash/RegExp.html)

It's very nice, well written, and doesn't require the ExternalInterface api... and because it's all actionscript there is less overhead with making the calls.

Take Care.

_Michael

mmm..pi..3.14..
03-11-2006, 05:09 AM
Too much code (larger file size)
Not as reliable, written entirely in actionscript it can't work for 100% of all regular expressions.

I'd probably only use that if I needed it to use regular expressions in a projector or something that wasn't on a browser. Still very impressive though, I figured it would be very unlikely that someone had not made something like that before.

MichaelxxOA
03-11-2006, 05:36 AM
Just a tool, and alot of development is done in Flash 6/7 so this is what will help. I meant no disrespect to the code you wrote. Take Care.

_Michael

mmm..pi..3.14..
03-12-2006, 04:29 AM
Yeah, I know, didn't think you were being disrespectful at all. Just think it would be helpful for some people. Actually wouldn't really matter if anybody liked it or not, only took me about 8 minutes to write, lol :)

rbz
03-18-2006, 04:28 AM
hi, i've been playing around with the cookie class, and i'm stucked on the following:

Mac Firefox 1.5: works ok
Mac Safari 2.0: setCookie doesn't answer, readCookie returns null
Mac IE 5.2: setCookie doesn't answer, readCookie doesn't answer
Virtual PC IE 6.0: works ok

i've tried passing expiration and path, and no answer

expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

button.onPress = function() {
CookieJar.setCookie("my_site", "choosen_lenguage", exp, "/");
};


any clues?

Xeef
03-26-2006, 06:32 PM
not sure if it's already in here or not

as i realy hate the TweenClass of flash here something


//i think it's called something like "bezierTween"
_root.createEmptyMovieClip("_mc", 0);
Show(Stage.width, Stage.width/3, Stage.width/3*2);
function Show(lenge, Begin, End) {
_mc.clear();
_mc.lineStyle(2, 0, 100);
//"+= 0.05" on this depends how many steps you get
for (S=0; S<1; S += 0.05) {
var cx = 3*Begin;
var bx = 3*(End-Begin)-cx;
var ax = lenge-cx-bx;
//
var S2 = S*S;
var S3 = S2*S;
//
var X = (ax*S3)+(bx*S2)+(cx*S);
_mc.moveTo(X, 100);
_mc.lineTo(X+1, 100);
}
}
//
_root.createEmptyMovieClip("Start", 1);
Start.beginFill(0, 100);
Start.lineTo(20, 0);
Start.lineTo(20, 20);
Start.lineTo(0, 20);
Start.lineTo(0, 0);
Start.endFill();
Start._y = 200;
Start._x = Stage.width/3;
Start.onPress = function() {
this.X = _xmouse;
Start.onEnterFrame = function() {
this._x -= this.X-_xmouse;
this.X = _xmouse;
Show(Stage.width, _root.Start._x, _root.End._x);
};
};
Start.onRelease = Start.onReleaseOutside=function () {
this.onEnterFrame = null;
};
//
_root.createEmptyMovieClip("End", 2);
End.beginFill(0, 100);
End.lineTo(20, 0);
End.lineTo(20, 20);
End.lineTo(0, 20);
End.lineTo(0, 0);
End.endFill();
End._y = 200;
End._x = Stage.width/3*2;
End.onPress = function() {
this.X = _xmouse;
End.onEnterFrame = function() {
this._x -= this.X-_xmouse;
this.X = _xmouse;
Show(Stage.width, _root.Start._x, _root.End._x);
};
};
End.onRelease = End.onReleaseOutside=function () {
this.onEnterFrame = null;
};


it isn't a class or ready to use (if somebody like make a class out of it ;) )
but it shoud demonstrate it good enoght so you can implement it your self

MichaelxxOA
03-27-2006, 12:16 AM
New Class added.. DateTime. Take Care.
_Michael

mymira
04-20-2006, 07:32 AM
very good

MichaelxxOA
04-21-2006, 09:58 PM
Wow I even got a cake... no one else gave me a cake!

very good

MichaelxxOA
04-22-2006, 01:14 PM
New utility added, DepthManager. Can be found here...

http://www.actionscript.org/forums/showthread.php3?t=103699

Take Care.
_Michael

MichaelxxOA
04-26-2006, 09:40 PM
Stack/Queue Data Structures added...

timmermansm
05-10-2006, 04:21 PM
Fun Fun Fun... yet another utility class for your guys' using pleasure.

Saved as, IdleUserWatcher.as


class IdleUserWatcher
{
// is the user active?
private var __isActive : Boolean = false;
// the id for the interval
private var intervalID : Number;
// how long to wait before calling is idle... default is 10 seconds
private var idleTime : Number = 1000;
// a list of all objects listening
private var listeners : Array;
// readonly property for isActive
public function get isActive () : Boolean
{
return __isActive;
}

public function IdleUserWatcher ( idleTime:Number )
{
if (idleTime != undefined)
{
this.idleTime = idleTime;
}

Mouse.addListener (this);
Key.addListener (this);
listeners = new Array();

}
/* Adds a listener to the listeners list */
public function addListener(listener:Object) : Boolean
{
for (var i:Number=0; i<listeners.length; i++)
{
if (listeners[i] == listener) return false;
}
listeners.push(listener);
return true;
}
/* Removes a listener from the listener list */
public function removeListener(listener:Object) : Boolean
{
for (var i:Number=0; i<listeners.length; i++)
{
if (listeners[i] == listener)
{
listeners.splice(i, 1);
return true;
}
}
return false;
}

/* Events */
private function onKeyDown () : Void
{
setIdleInterval();
}
private function onMouseMove () : Void
{
setIdleInterval();
}

/* Private Methods */
private function setIdleInterval()
{
this.__isActive = true;
clearInterval (this.intervalID);
this.intervalID = setInterval (this, "broadcastIdle", this.idleTime, this);
}
private function broadcastIdle(watcher:IdleUserWatcher) :Void
{
watcher.__isActive = false;
for (var i:Number=0; i<listeners.length; i++)
{
listeners[i].onUserIdle();
}
clearInterval(watcher.intervalID);
}
}



This is an EXTREMELY simple class to use, here is what the code looks like to use it in an fla.


// here you simply tell the object how long to wait for the user
// before deciding he/she is inactive
var idleWatcher = new IdleUserWatcher(1000);

// then we register an object to listen for the onUserIdle() event from
// our IdleUserWatcher object
idleWatcher.addListener(_root);

// IdleUserWatcher has one property, it returns whether or not the user is active
trace(idleWatcher.isActive);

function onUserIdle()
{
trace("BUZZ!!! COME BACK!!");
}


Have fun with this.. I've officially decided that every site I do will now have a screensaver! WOOT!
_Michael


This class works great, absolutely fantastic!!!
The only thing I can't get out of it is the possibility to give a function when the user isn't Idle... (so when you do move your mouse when the screensaver is on.)

Thanks in advance.

gogole
05-12-2006, 06:30 PM
i dont know anything about this stuff but i can see it good stuff to know,learning it at the moment.

MichaelxxOA
05-31-2006, 01:03 AM
Background class added...

Michael

Jesse
05-31-2006, 02:32 AM
Another good'ne. Thanks mate.

A great feature would be to be able to set the background to an image too...

Cota
05-31-2006, 02:41 AM
Michael is the man with these things...

A1A2
06-06-2006, 08:40 AM
Hey, Michael,

Really appreciate your effort, and I was wondering if you could maybe provide a bit more info on the QueryString class. What does it do, and how to apply it?

Again, Thanks!

Al

MichaelxxOA
07-22-2006, 01:11 AM
Added the SoundManager, take care.

Michael

Flash Gordon
07-22-2006, 01:15 AM
Michael, add you .jslf-thing extention. That was a really nice thread.

MichaelxxOA
07-22-2006, 08:18 AM
Which thread was that?

Michael

Flash Gordon
07-22-2006, 05:33 PM
The one where you mass rename objects in the library. I thought that was really neat, but maybe it doesn't belong here. Maybe we can get CyanBlue to update his 5000th post: most useful threads. ;)

MichaelxxOA
07-22-2006, 05:37 PM
Lol, I should probably make a more reusable version then, because that one was tailored specifically to his needs! :D

Michael

MichaelxxOA
07-23-2006, 05:49 AM
Updated with tabbing order.

Michael

MichaelxxOA
07-24-2006, 09:38 PM
Zip added

Flash Gordon
07-24-2006, 09:42 PM
Hey Michael,

Thanks for the zip of all the class, but here is a dumb question (i guess). What is the ~ appended to certain classes for?

MichaelxxOA
07-24-2006, 09:49 PM
It's because I use a text-editor called VI, when you edit a file in VI it doesn't actually open and edit the file itself, instead it creates these temporary backup files and edits them... it then saves a copy of the file before you last opened it as filename.as~, make sense?

Michael

Flash Gordon
07-24-2006, 09:51 PM
yup.

:)

[ btw, I though VI was a linux thing ].

MichaelxxOA
07-24-2006, 11:00 PM
Updated with my EventBroadcaster class... sorry for the poor example, I will be writing an article soon.

Michael

MichaelxxOA
07-24-2006, 11:01 PM
yup.

:)

[ btw, I though VI was a linux thing ].

VI is a linux thing, but they have a distribution of it called VIM... I worked with linux through school, and so had used VI alot, and fell in love with it.

It's incredibly powerful if you spend the time to learn it.

Michael

MichaelxxOA
07-25-2006, 12:09 AM
Hey St33v why don't you start a new thread in Actionscript 2.0, and I will post a link on the first page with the rest of my classes to the thread, that way if anyone has questions, it's all tidy and kept in a single thread... we made the mistake of merging, but with all of my latest classes I have been posting new threads, and then linking to them.

Take care.
Michael

____
07-25-2006, 12:10 AM
It's because I use a text-editor called VI, when you edit a file in VI it doesn't actually open and edit the file itself, instead it creates these temporary backup files and edits them... it then saves a copy of the file before you last opened it as filename.as~, make sense?

Michael


its insanely annoying

ashes999
08-03-2006, 01:15 PM
So, is there a CMS or some public location where all of these classes are located? (The discussion is on page 8 of this thread, that's a few months ago...)

These utilities look VERY useful, I just don't want to read 13 pages of posts again to find them when I need them!

blockage
10-18-2006, 12:03 PM
Michael thanks for all your hard work - trully excellent!

One thing though - I'm not able to get your UrlQuery working in Safari. After doing a bit of debuging it seems the external interface always returns null which I think has something to do with the way Safari serializes the return value.

Anyone had any similar experince or got any good ideas?

blockage
10-29-2006, 08:45 PM
Buginajar has fix UrlQuery in safari - you can find this here...
http://www.actionscript.org/forums/showthread.php3?t=119964

mojito
12-19-2006, 02:06 PM
Looks like will be a great script. It cant compile or find the following...

import flash.external.ExternalInterface;

Ruben
12-19-2006, 02:29 PM
Are you sure you're working with Flash 8?

- Ruben

MichaelxxOA
12-19-2006, 04:27 PM
Updated the list to include Buginjar's fixed version of the URLQuery class. Thanks guys, :-P.


Michael

mojito
12-19-2006, 04:30 PM
yes, Iam sure im using flash 8 pro ,where can i find the classes in the first run folder ?

majicassassin
12-29-2006, 06:42 PM
If anyone's interested in an ArrayList-type functionality (quickly skimmed this thread, didn't see anything that was quite the same)
http://www.actionscript.org/forums/showthread.php3?t=124410&highlight=ArrayList

zfoley
02-21-2007, 06:44 PM
Not sure why - but cookie jar does not work in Safari. I suspect its a security issue since it returns null.

blockage
02-26-2007, 07:37 AM
Not sure I really get the need for the cookie jar class - wouldn't a shared object be a better?

Anyhow based on the what we discovered about the AS external interfaces and Safari (thanks to buginajar) you might want to try removing the function names from the javascript. So the following:

private static var write_cookie:String = "function writeCookie(args){var cookie_string = args[0] + \"=\" + escape(args[1]);alert(cookie_string);switch (args.length){case 3:cookie_string += \"expires=\" + args[2];break;case 4:cookie_string += \"path=\" + args[3];break;case 5:cookie_string += \"domain=\" + args[4];break;case 6:cookie_string += args[5];break;}document.cookie = cookie_string;}";

private static var get_cookie:String = "function getCookie(name){var allcookies = document.cookie;var pos = allcookies.indexOf(name + \"=\");if (pos != -1) {var start = allcookies.indexOf(\"=\", pos) + 1;var end = allcookies.indexOf(\";\", start);if (end == -1) end = allcookies.length;var value = allcookies.substring(start, end);value = unescape(value);return value;}}";

private static var remove_cookie:String = "function removeCookie(name){var cookie = name + \"=\";cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';document.cookie = cookie;}";



To this:


private static var write_cookie:String = "function (args){var cookie_string = args[0] + \"=\" + escape(args[1]);alert(cookie_string);switch (args.length){case 3:cookie_string += \"expires=\" + args[2];break;case 4:cookie_string += \"path=\" + args[3];break;case 5:cookie_string += \"domain=\" + args[4];break;case 6:cookie_string += args[5];break;}document.cookie = cookie_string;}";

private static var get_cookie:String = "function (name){var allcookies = document.cookie;var pos = allcookies.indexOf(name + \"=\");if (pos != -1) {var start = allcookies.indexOf(\"=\", pos) + 1;var end = allcookies.indexOf(\";\", start);if (end == -1) end = allcookies.length;var value = allcookies.substring(start, end);value = unescape(value);return value;}}";

private static var remove_cookie:String = "function (name){var cookie = name + \"=\";cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';document.cookie = cookie;}";



Sorry I don't have a Mac to hand at the moment so can't test this.
b

zfoley
02-26-2007, 05:58 PM
Cookie jar is just one example of being able to maintian and execute javascript from within flash. I agree that shared objects are in most cases better, but because they require users to allow them in some cases, many sites prefer javascript cookies. Plus, the javascript cookie is available to the browser whereas the shared object is only available to the flash plugin.

I will test your code to see if it works. Would you mind posting what you found out about Safari here?

Thanks,
PSturgeon

zfoley
02-26-2007, 06:13 PM
Just tested the code on a Mac and PC - works in IE7 amd FF2.0 for PC and Safari and FF2.0 for Mac! Thanks blockage and buginajar

MichaelxxOA
02-26-2007, 11:36 PM
yeah guys, thanks. you're all awesome.

blockage
02-27-2007, 10:47 AM
Would you mind posting what you found out about Safari here?

Not at all, but there isn't much more to say except that Safari doesn't like named functions.

ExternalInterface.call("function myFunc () { return true; }") // wont wont work in Safari

ExternalInterface.call("function () { r