Author Archive

How to Pad a Number with Zeros + Simple Counter

Tuesday, May 25th, 2010

At some point you may need to display a number that must always occupy a predetermined number of character spaces. An example would be a rolling game timer with a 5 digit display. For example, when the timer hits 33 seconds, the digits would display like so: 0 0 0 3 3

Categories : Nuts & Bolts
Comments (0)

Freeing up memory for Garbage Collection

Sunday, May 2nd, 2010

Something that I’ve been noticing lately is the need to pay close attention to how you are cleaning up your objects after you are done with them.

I’ve been working with a great as3 debugging tool called “De MonsterDebugger”. Strange name but great tool. Check it out here: http://www.demonsterdebugger.com/

Comments (0)

Hidden Games in as3blog.org

Friday, April 2nd, 2010

I just realized that there are some hidden games in my banner. This may seem like a strange statement since I made the banner and all the artwork. Well, originally the banner was a concept design for a company that we do projects for called “ThinkFun”. I stripped down the banner but apparently left some ‘hidden’ games.. See if you can find the games hidden in the header banner of this site! I believe there are anywhere from 3 to 6 or so.

Categories : General
Comments (2)

How to use Classes in your Project

Thursday, April 1st, 2010

Many of the examples that I use in my blog come in the form of a “Class” file. Without going into too deep an explanation, I will attempt to explain how to implement a class into your project. The following is a class for our example:

Categories : Nuts & Bolts
Comments (0)

How to dispatch a custom event

Thursday, March 11th, 2010

This is going to be a very simple example of how to dispatch an event. In actionscript 3, you dispatch an event by extending the EventDispatcher class. I’m not going to get into a big complicated explanation right now, but I will show you a couple of simple examples.

Categories : Nuts & Bolts
Comments (6)

How to create an AS3 game grid

Monday, March 1st, 2010

One things that you have to do a lot when developing grid based games is obviously lay out the grid. This is confusing to a lot of people but is really quite simple. I created a simple class just for this blog to demonstrate how this can be achieved.

Categories : Game Stuff
Comments (6)

Load AS2 SWF into your AS3 Project

Tuesday, February 16th, 2010

There is a game that I have been working on that I’ve had to load into an as3 interface and I noticed that my previous class will not work to do this.
There were a few modifications that I had to make… Here is the class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SWFLoader Class by Rick Nuthman
// 2.16.10
//
// Usage:
/*
var game:SWFLoaderAs2 = new SWFLoaderAs2("yourSwf.swf",20,0)
game.dispatcher.addEventListener("ready", gameLoaded);
function gameLoaded(event:Event){
   
    addChild(game);
}
*/


package com.frigidfish{

    import flash.display.Sprite;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.events.EventDispatcher;       

    public class SWFLoaderAs2 extends Sprite {     
       
        public var dispatcher:EventDispatcher   = new EventDispatcher();
        private var contentLoader:Loader;      
       
       
        public function SWFLoaderAs2(pathToTheContent,x,y) {
           
            this.x = x;
            this.y = y;
            loadSWF(pathToTheContent);
        }
           
        private function loadSWF(pathToTheContent):void {
           
            var request:URLRequest  = new URLRequest(pathToTheContent);
            contentLoader           = new Loader();
            contentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,swfLoaded);
            contentLoader.load(request);
        }

        private function swfLoaded(e:Event):void {
           
            addChild(contentLoader);
            dispatcher.dispatchEvent(new Event("ready"));                  
        }
    }
}

usage:

Comments (0)

Quick and easy GetURL class

Monday, February 15th, 2010

Here is a quick basic url loader for quickly adding links to buttons and movie clips:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// GetURL Class by Rick Nuthman
// 10.4.09
// Usage:
// new GetURL("url", "target");

package com.frigidfish{
   
    import flash.net.*;
   
    public class GetURL{
       
        private var request:URLRequest;
       
        public function GetURL(url:String, target = '_self'){
           
            request = new URLRequest(url);         
            navigateToURL(request, target);
           
        }
    }
}

It’s just a bare bones script that works like the old getURL method from actionscript 2.
It defaults to opening the url in a blank page, but you can change this by modifying the 2nd parameter.

Comments (5)

Load SWF via Actionscript 3 with this class

Monday, February 15th, 2010

Here is a class that you can use to load swf’s into an object that you can display or do whatever you’d like with:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SWFLoader Class by Rick Nuthman
// 2.10.10
//
// Usage:
/*
var mySWF:Object;
mySWF = SWFLoader.create("urlToSWF.swf", 0,0);
mySWF.dispatcher.addEventListener("ready", displaySwf);
function displaySwf(event:Event){
    addChild(mySWF.swf);
}
*/


package com.frigidfish{

    import flash.display.Sprite;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.events.EventDispatcher

    public class SWFLoader{        

        public function SWFLoader() {
        }

        public static function create(url, x=0,y=0):Object {
           
            var loaded:Event                = new Event("ready");
            var dispatcher:EventDispatcher  = new EventDispatcher();
            var swf:Sprite                  = new Sprite  ;
            var mLoader:Loader              = new Loader  ;
            var obj:Object                  = new Object;
           
            obj.swf = swf;
            obj.dispatcher = dispatcher;
           
            swf.x = x;
            swf.y = y;
           
            var mRequest:URLRequest = new URLRequest(url);
            mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,swfLoaded);

            mLoader.load(mRequest);

            function swfLoaded(event:Event) {
                var target = event.currentTarget.content;              
                swf.addChild(target);  
                dispatcher.dispatchEvent(loaded);
            }
           
            return obj;
        }
    }
}

You don’t need to make an instance of the class, just use the static function ‘create’ like so:

Categories : General
Comments (2)

Send/Receive Variables from Actionscript 3 & PHP

Sunday, February 14th, 2010

Below is a class that I made that can be used to send a group of variables to a php script on a server and receive the results. I use this all the time in many of my projects!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// FlashPHP Class by Rick Nuthman
// 8.28.09
// Constructor receives 2 arguments:
// url:String - The url to the PHP file
// flashVars:Object - An object that contains variables to be sent to the url
//
// The class dispatches 1 event called "ready" once the php transaction is complete.<a href='http://www.as3blog.org/wp-content/uploads/2010/02/FlashPHP_example.zip'>FlashPHP_example</a>
// listen for this event. Once it's received you can access returned variabled from receievedVars.

package com.frigidfish{

    import flash.net.URLVariables;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLRequestMethod;
    import flash.events.EventDispatcher;
    import flash.events.Event;

    public class FlashPHP extends EventDispatcher {
       
        // Public Properties
        public var receivedVars:URLVariables;      
       
        // Private Properties
        private var url:String;    
        private var flashVars:Object;
        private var request:URLRequest;
       
        private var completeEvent:Event              = new Event("ready");
        private var variables:URLVariables           = new URLVariables();
        private var loader:URLLoader                 = new URLLoader();

        public function FlashPHP(url:String, flashVars:Object) {
           
            this.flashVars                      = flashVars;
            this.url                            = url+"?r="+ new Date().getTime();
           
            parseVariables();
        }

        // Private Methods
        private function parseVariables() {
           
            for (var item in flashVars) {
               
                variables[item] = flashVars[item];             
            }
           
            sendVariables();
        }

        private function sendVariables() {
           
            request                                 = new URLRequest(url);
            request.method                          = URLRequestMethod.POST;
            request.data                            = variables;
           
            loader.dataFormat                       = URLLoaderDataFormat.VARIABLES;           
            loader.addEventListener(Event.COMPLETE, variablesAreLoaded);
            loader.load(request);
        }

        function variablesAreLoaded(event:Event) {
           
            receivedVars                            = new URLVariables(loader.data);
            dispatchEvent(completeEvent);          
        }
    }
}

Here is an example of how to implement it:

Comments (32)