Drawing an Owl for my new upcoming small children’s game

Categories game art, games, MyArtWork


This will be my first game in collaboration with my dear wife. She came up with the idea, and I am trilled to finally draw her in game development, little by little. I won’t reveal too much about it for now, it will be available first in Romanian and then translated to English. The game will be for really small children, our son inspired my wife and most likely will be the beta tester :).

I will have to draw a lot for this game. To get my drawing in a better shape I have subscribed to https://www.schoolism.com. I am taking the Environment Design with Nathan Fowkes and Gesture Drawing with Alex Woo, and last week I went trough Drawing Fundamentals with Thomas Fluharty. I will be staying on Schoolism for sometime, since I have probably discovered the quickest way to improve my art skills. They are awesome!

Here is me, drawing the owl from above.

I hope you liked it 🙂



Share this

Creating Mr. Nussbaum’s Boardwalk Challenge

Categories games

From time to time, when the stars align just the right way, Greg and I make awesome educational games. He is a fantastic Game Designer, and his games are truly unique.

I usually take the opportunity and push it a bit beyond my own capabilities. This obviously stretches the development time and leaves me drained of all energy. But I enjoy every second, and I am always extremely proud with the end result.

In March 2016 my beautiful son arrives into this wonderful world. Never before I felt so happy in my life. I took a couple of months off, so I can help the new mommy and also adjust to the new parent role.

After 4 months, exhausted, thrilled, still adjusting to this new role and the huge responsibility of being a parent, I slowly go back to my own game development. About this time, Greg reaches out to me with a new game. I said OK, we will do it,  but have to start in October. That’s when the baby will be 6 months, and mommy goes back to work, and in my naivety I thought my own game will be finished. But I set a date, and said the work on the new game will start then no matter what.

So it id.

I have received the detailed description from Greg, so the development is officially on the way. Let me take this time to tell you something, Greg’s descriptions document is so good and well planned that it doesn’t change throughout the development. This is extremely rare, and one of the many reasons I enjoy working with him. The majority of software failures are due to a bad or incomplete plan.

With a good plan in hand, it’s time to decide, flash or HTML5. We decide it is a good idea to publish it in HTM5, so that it can run on iPad, or Android tablets and will more or less future proof. It took a couple of days to investigate what’s out there, and what tools we can use to reach our goals. I knew I wanted some sort of OOP programming that will be then converted (transpiled) to JavaScript and HTML5. I also wanted the game to work the same on iPad, Android and PC with all the various browsers out there.

I remembered something about HAXE from somewhere, so I started looking into it. After trying out different engines, I found that Flambe was working well across different browsers and OS, and also was able to publish the code to swf. So flambe it is.

Moving from FlashDevelop to HaxeDevelop was easy, making Flambe work, was not. It needed some patch in the source code, nothing too hard, and after some good googling around I find exactly what needs to be done, but I am afraid that for beginners, this might be off-putting.

We are up and running, so actual coding will start soon, but first I need to structure the work ahead, I break down all the major tasks into smaller ones. The game is made up by 5 games. You play the first, game to earn points that you use in order to gain access to other 4 fun games, and you play those games in order to gain points that you can exchange for items in the store. These items, get “printed” on certificates that kids can save to their devices.

The first game requires you to arrange the numbers on the screen in the right order, I named it “Earn Tokens”. Nothing too complicated to do in here, the prototype was up and running in no time.

The second game, is “Whack the Pirates”. By this time, I was already making the layouts, establishing the main themes, but didn’t settled for a look yet. First code and layout, then later when everything pretty much works the way it supposed to, I’ll move on to the artwork.

So far everything works pretty good, there is an annoying thing in Whack the pirates, where because of Flambe limitation, I can’t use masks properly, so that the characters hide when going back into their holes. But things move well and it seems that this new Haxe/Flambe thing is not bad at all, and I am very happy with the progress being made.

At this time it’s worth mentioning that development was being done under some tight schedule, in the time when the baby was sleeping, and, when mommy got back from work. Leaving me with almost zero personal downtime, before going to sleep.

Moving forward to Air Hockey, I realized it’s going to be a bit more challenging, but nothing that I can’t handle. For Air Hockey I just used some simple trigonometry, and simple point/distance collision detection, nothing too fancy, it worked.

Next one will be Ski-ball. After looking at all the SkeeBall games on YouTube that I can find, I realized, I won’t be able to get away with some simple tricks, I actually started to build it using the same tricks in Air Hokey, but it didn’t cut it this time. It needed a physics engine. After some research, I found Nape. It was an excellent choice, it did what I wanted and I will soon discover It did even more stuff that I didn’t even know I needed.

In order to edit the physics shapes you need a physics editor that can export the shapes back to Haxe, for this I bought PhysicsEditor. It does a good job at editing the shapes, but you need to trim the generated output code, so that you can use it effectively inside your game.

Soon after the Ski-ball game prototype was done, we hit a problem. The game won’t scale nicely. There is now way to scale things inside in a similar way to the flash based display list, so to make it work, you need to apply a scale calculation to everything, from math calculations inside the Air hockey game, to individual graphics. At this point I was afraid that I will need to apply the same scale calculations to each and every single node in the data provided by the physics editor, a task that would be extremely time consuming, not to mention every time that you would need to make an adjustment you would redo the whole process. Nightmare! Luckily, the shapes have a scale property, and the task to adjust for the scale is not that bad.

Finally I move to the final game Roll the Ball, and I soon discover the sensors inside Nape and I am in awe. They are awesome! Nape is Awesome!

Prototyping done.

Without getting too much into details, Flambe is really cool, but beware of the limitations, no sound on some iOS devices, no easy system for adjusting to different screen resolutions, no masking, no printing, no easy way to combine multiple image into a single one, for say download or other uses (like in character customization), and the entity/component system might be a bit awkward in the beginning. But if you don’t need printing, mask, downloading generated images, it’s a pretty solid engine, that works well on different devices, inside the different browsers. The sound issue is a problem not exactly with flambe, rather with Apple’s way of doing things, so much for “promoting” HTML5 on their devices.

After the coding part was mostly done I moved to the Art Work, based on the already made layouts and the place holders characters.

Some of the Art Work was inspired by the works of http://danielmerriam.com

After the Art Work was done, I added background music from http://incompetech.com/ and sound that I recorded with my phone, making noise using the toys my son plays with.

After some more testing, and bug fixing, the game is completed:


I hope kids will enjoy it for many years to come, and if you like it do share it!

Thank you for reading 🙂




Share this

Abstract #1

Categories abstract paintings, MyArtWork

Today I have installed a brand new program, which I absolutely adore, it’s called ArtRage.

I am starting (hopefully) a new habit of making abstract paintings.

The rule is simple, pick an abstract piece by some of the great abstract artists, and paint something similar, in about 1 to 2 hours, when I get a bit of time-off from my regular work. The scope is to learn how to paint abstract original artwork, but until then, copy FTW!

The #1 is inspired by Alberto Burri Sacco.abstract1

Share this

Background FX live session

Categories Actionscript, game art, Starling

Using my Open Source Particle Designer tool, Angulex to design the background effects in the MathSumRun Trophy Room.

After exploring a bit with the different designs, I settle for a simple colored background particles with some nice starlight textures. This is typical with my design process, I usually start and explore different and more complicated designs, then subtract elements that I find they have too much of a distraction characteristic. It’s a fine line from just enough decorum to over doing it.

The tool lets me explore different options with ease, but it does have some quirks and UI bugs (layering order mishaps). I (obviously) know how to bypass them and until I am releasing MathSumRun, I don’t think I will have the time to fix the bugs.

Also the different textures and backgrounds needed have to be hard-coded, which is probably the first thing I will need to change in the future (after bug-fixing).

For now, it does it’s job perfectly and I can focus on the development of my game 🙂

Share this

Sharing Achievement Badges for MathSumRun

Categories game art

The final set of badges in MathSumRun, this ones rewards you for sharing your achievements on Twitter or Facebook.

Math Fan, for your first share.

mathsumrun fan

Math Preacher, for your first 10 shares on Twitter or Facebook.

mathsumrun preacher

Math Evangelist, for the ultimate player, 30 shares will get you this badge.

mathsumrun evangelist

With this set, I have completed all the achievements badges for the game. Time to setup the remaining screens and implement (code) them in the game. Just in time since Friday is here, so time to relax and enjoy the weekend!

To get the latest updates on the game, subscribe to the MathSumRun Facebook page.

Share this

Time Achievement Badges for MathSumRun

Categories game art, games

Today I am following the previous set, with the new Time Badges you will be able to earn in MathSumRun.

Math Pioneer, you will earn this one after 30 min spent in the game.

mathsumrun pioneer

Math Enthusiast, to get this one you will have to spend 1 hour in the game.

mathsumrun Enthusiast

Math Devotee, to collect this one you will need to accumulate 2 hours in the game.

mathsumrun devotee

To get the latest updates on the game, subscribe to the MathSumRun Facebook page.

Share this

Achievement Badges for MathSumRun

Categories game art, games

MathSumRun is almost complete and now I am in the process of designing different achievement badges, here are the first ones.

Addition Scholar Badge. You will earn this one after answering correctly 30 addition problems in a perfect sequence.

addition scholar badge

Addition Master, you will have to solve, 100 addition problems to earn this one. You will need some concentration to achieve this awesome feat.


The hardest one, Addition Tycoon. You will have to answer without any mistake all 945 problems in the game, making a perfect game.


A few others will follow shortly.

To get the latest updates on the game, subscribe to the MathSumRun Facebook page.


Share this

Study for Game Backgrounds

Categories game art, games, level design

During my research for the level designs in my upcoming game MathSumRun, I have stumbled upon some interesting references you can use for drawing your backgrounds.

Most of the nicest stuff out there, rests neatly organized on Pinterest, which is a heaven for digital hoarders collectors of fine imagery. The stuff you find on Pinterest is usually a few magnitudes better than the stuff you find on a Google search, or in other popular places were you might search for inspiration, like DeviantArt or Behance.

Diving in 🙂

The Art Of Aquascaping. One of my favorites references, aquascaping designs seemed to be a perfect fit for side scrolling games. You can easily use them if your game has a jungle theme, but you can also modify them to look like they are out of this world,  by changing the color and texture, this is  exactly what I did with one of my levels as you can see here:

mathsumrun level

Backgrounds from films, with the animation ones being the best sources. One1more2time3’s Weblog has some really nice backgrounds like this one:

Trees! Just looking at trees, you will often find really interesting shapes and landscapes. I loved this tree so much, I made a level based on it.

tree level ref

I have found only one Facebook group for Background paintings, which is a bit weird since backgrounds are so important. Oh well, at least it’s a very good group and there are nice posts, like this awesome Art Director of Environments from Zootopia.

Back to my new favorite web place to hang around (and collect stuff), I have found the Character Design References, which has a few background collections like this: Environment Design | Abyss, so ctr+f in your browser, write “Environment Design” and check them all out.

While looking at the history of background design, I found the amassing work of Tyrus Wong. His early paintings were used as the style for the backgrounds in Bambi (1942) . Fun fact, he makes kites since the year he got retired in 1968, he is 105 🙂

I am sure I will ad some more links in here, until then, do share your favorite sources of inspiration  for your background drawings in the comments.

Happy drawing 🙂


Share this

Quick (dirty) buttons for your Starling app

Categories Actionscript, games, Starling

Sometimes you need to control parts of you app for testing so a a quick way to build some buttons in Starling is very useful. In my case, I needed to test different parts of MathSumRun and adding an external library for this purpose only is an overkill.

buttons controll

Here is the dirty code for this:


  1. package com.cosmindolha.mathsumrun
  2. {
  3.     //import com.cosmindolha.mathsumrun.DataDispatcher;
  4.     import com.utils.Delay;
  5.     import starling.display.Canvas;
  6.     import starling.display.Sprite;
  7.     import starling.events.Touch;
  8.     import starling.events.TouchEvent;
  9.     import starling.events.TouchPhase;
  10.     import starling.text.TextField;
  11.     /**
  12.      * ...
  13.      * @author Cosmin Dolha
  14.      */
  15.     public class AppControl extends Sprite
  16.     {
  17.         //private var disp:DataDispatcher;
  19.         public function AppControl()
  20.         {
  21.             x = 1150;
  22.             y = 50;
  23.             //disp = DataDispatcher.getDisp();
  25.             button("Game Over", onGameOver, 0, 0, 75);
  26.             button("Level Done", onLevelFinished, 0, 30, 75);
  27.             button("End Game", onGameEnded, 0, 60, 75);
  28.             button("Time Up!", onTimeUp, 0, 90, 75);
  30.             incrButtons("Stage", onPrevStage, onNextStage, 120);
  31.             incrButtons("Level", onPrevLevel, onNextLevel, 150);
  32.             incrButtons("Qstn", onPrevQuestion, onNextQuestion, 180);
  35.         }
  36.         private function onPrevQuestion():void
  37.         {
  39.         }
  40.         private function onNextQuestion():void
  41.         {
  43.         }      
  44.         private function onPrevLevel():void
  45.         {
  47.         }
  48.         private function onNextLevel():void
  49.         {
  51.         }  
  52.         private function onPrevStage():void
  53.         {
  55.         }
  56.         private function onNextStage():void
  57.         {
  59.         }
  60.         private function onTimeUp():void
  61.         {
  62.             trace("on time up");
  63.         }      
  64.         private function onGameEnded():void
  65.         {
  66.             trace("on game end");
  67.         }
  68.         private function onLevelFinished():void
  69.         {
  70.             trace("level finished press");
  71.         }      
  72.         private function onGameOver():void
  73.         {
  74.             trace("game over press");
  75.         }
  76.         private function incrButtons(str:String, prevFunc:Function, nextFunc:Function, y:Number):void
  77.         {
  78.             button("< -", prevFunc, 0, y, 35);
  79.             var labelField:TextField = new TextField(35, 20, str, "Verdana", 9, 0xffffff, false);
  80.             labelField.touchable = false;
  81.             addChild(labelField);
  82.             labelField.x = 20;
  83.             labelField.y = y;
  84.             button("->", nextFunc, 40, y, 35);
  85.         }
  86.         private function button(str:String, func:Function, x:Number, y:Number, w:Number):void
  87.         {
  88.             var sp:Sprite = new Sprite();
  89.             sp.x = x;
  90.             sp.y = y;
  92.             var canvas:Canvas = new Canvas();
  93.             canvas.beginFill(0xffffff);
  95.             canvas.drawRectangle(0, 0, w, 25);
  96.             canvas.endFill();
  98.             var txt:TextField = new TextField(w, 20, str, "Verdana", 9, 0xffffff, false);
  99.             txt.touchable = false;
  100.             canvas.alpha = .2;
  102.             sp.addChild(canvas);
  103.             sp.addChild(txt);
  104.             sp.addEventListener(TouchEvent.TOUCH, onTouch);
  105.             function onTouch(e:TouchEvent):void
  106.             {  
  107.                 var touch:Touch = e.getTouch(stage, TouchPhase.BEGAN);
  108.                 if (touch == null) return
  109.                 func();
  110.                 canvas.alpha = .5;
  111.                 var returnDelay:Delay = new Delay(returnAlpha, 100);
  112.                 function returnAlpha():void
  113.                 {
  114.                     canvas.alpha = .2;
  115.                 }
  116.             }
  117.             addChild(sp);
  119.         }
  120.     }
  122. }

And the Delay class:


  1. package com.utils
  2. {
  3.     import flash.events.TimerEvent;
  4.     import flash.utils.Timer;
  5.     public class Delay
  6.     {
  7.         private var timer:Timer;   
  8.         private var delayedFunction:Function;
  9.         public function Delay(functionToDelay:Function, delayMilisec:Number)
  10.         {
  11.             this.delayedFunction = functionToDelay;
  12.             timer = new Timer(delayMilisec, 1);
  13.             timer.addEventListener(TimerEvent.TIMER_COMPLETE, callDelayedFunction);
  14.             timer.start();
  15.         }  
  16.         private function callDelayedFunction(event:TimerEvent):void
  17.         {
  18.             timer.removeEventListener(TimerEvent.TIMER_COMPLETE, callDelayedFunction);
  19.             delayedFunction();
  20.         }
  21.     }
  22. }
Share this

Starling Particle Designer – HackTM2015

Categories Actionscript, games

This weekend I went to HackTM2015 and started the development of my Starling Particle Designer.


This tool will be used to make better Particle Effects for my MathSumRun game.

The scope is to design the particle effects directly on my iPad, so I can push the effects to the limits, while still achieving good FPS.

The Starling Particle Designer source sits on GitHub at: ParticleDesigner

To test it on your iPad, you need to have a Jailbreak device and get the ipa file from here.
To install it on my iPad I use ifunbox.

Development is done for iPad 2 with iOS 6. Support for retina devices will be added at a later time.

Share this

If you upgraded to Starling 1.7 and your app is broken, check your assets manager

Categories Actionscript

After updating to Starling 1.7, my game stopped compiling. After a quick debugging, I found the problem in the assets manager. Narrowing it down, it seems that the getTexture returns null if I try to load an atlas texture.

To fix it, change:


  1. var elemTexture:Texture = resources.assets.getTexture("elements");         
  2. var elemXml:XML = new XML(resources.assets.getXml("elements"));
  3. var elemAtlas:TextureAtlas = resources.assets.getTextureAtlas("elements");



  1. var elemAtlas:TextureAtlas = resources.assets.getTextureAtlas("elements");

My assets are named: “elements.png” and “elements.xml”

In my game resources is a separate class that just loads all the elements, and the assets var is set to public, it looks like this:


  1. package com.cosmindolha.mathrun
  2. {
  3.     import flash.events.TimerEvent;
  4.     import flash.filesystem.File;
  6.     import starling.events.Event;
  7.     import starling.utils.AssetManager;
  9.     /**
  10.      * ...
  11.      * @author ... Cosmin Dolha ~ contact@cosmindolha.com
  12.      */
  13.     public class Resource
  14.     {
  15.         public var assets:AssetManager;
  17.         private var disp:DataDispatcher;
  19.         public function Resource(dd:DataDispatcher)
  20.         {
  21.             disp = dd;
  23.             assets = new AssetManager();
  25.             assets.keepAtlasXmls = true;
  27.             var appDir:File = File.applicationDirectory;
  29.             assets.enqueue(appDir.resolvePath("assets"));
  31.             assets.addEventListener(Event.IO_ERROR, onError)
  33.             assets.loadQueue(function(ratio:Number):void
  34.             {
  35.             if (ratio == 1.0)
  36.             {
  37.                 //trace("asstes loaded");
  38.                 disp.assetsLoaded();
  39.             }
  40.             });
  41.         }
  43.         private function onError(e:Event):void
  44.         {
  45.                 trace(e.data);
  46.         }
  48.     }
  50. }
Share this

Unity 3D Countdown script, using C#, for flash developers

Categories Unity 3D

First you need a GameObject GUI text, a GUI text is similar to flash TextField.  You create one, by going to GameObject>Create Other>GUI Text. GameObject is similar to DisplayObject in actionscript.

Scripts cannot exists without being assigned to a GameObject in the scene, there is no document class like in AS3. Luckily there is such a thing as an empty game object that we can use to assign scripts to it. To create one,  go to GameObject>Create Empty, name it whatever you want, mine is “TimerController”.

Creating our script:

Go to the Project panel, Assets and right click>Create>C# Script, you can name it whatever you want, mine is “CountdownTimer”. A file will be created in your assets folder with the extension .cs. (in our case “CountdownTimer.cs”).

Now we need to add our script to our empty game object “TimerController”, to do this, make sure your empty GameObject is selected (in the Hierarchy panel), then drag and drop your script (from the Project>Assets panel) to the Inspector panel. You can also assign a new script (called a Component in Unity), by selecting your GameObject, and clicking on your “Add Component” button, and in your search box, type your script name, and click it to assign it.

There is one thing we need to do before we jump to the countdown code, because we cannot access assign text to a GUI Text GameObject directly via the  guiText property (it is read only), like say someTextFiled.text = “my Text” in AS3, we need to add a public var to an assigned script of the GUI text we want to access (weird, I know).

Create a new script, I named it TextLink.cs, and add a “public string text” and assign it to guiText.text = text; in the update method. The script should look like:

  1. using UnityEngine;
  2. using System.Collections;
  4. public class TextLink : MonoBehaviour {
  6. public string text;
  7. // Use this for initialization
  8. void Start () {
  10. }
  12. // Update is called once per frame
  13. void Update () {
  15. guiText.text = text;
  17. }
  18. }

Coding our Countdown timer.

After you open your “CountdownTimer.cs”script in MonoDevelop, you see there are two methods, Start and Update. Start is similar to your init class method in AS3, and Update is similar to your EnterFrame event.

  1. using System;
  2. using System.Timers;
  4. public class CountdownTimer : MonoBehaviour {
  6. private GameObject timerTextfield;
  7. private int countTime;
  8. private Timer timer;
  10. // Use this for initialization
  11. void Start () {
  13. countTime = 120;
  15. timer = new Timer(1000);
  17. timerTextfield = GameObject.Find("CountdownTextfield");
  19. timer.Elapsed += new ElapsedEventHandler(TimerTick);
  20. timer.Start();
  22. }
  23. void TimerTick(object o, System.EventArgs e)
  24. {
  25. countTime--;
  26. Debug.Log(countTime);
  28. }
  29. // Update is called once per frame
  30. void Update () {
  32. if (countTime &gt; 0) {
  34. } else {
  36. timer.Stop();
  38. }
  40. TimeSpan t = TimeSpan.FromSeconds (countTime);
  42. timerTextfield.GetComponent ().text = string.Format ("{0:0}:{1:00}", t.Minutes, t.Seconds);
  44. }
  45. }

One major difference we see, is that we cast the var type before the var name, so while in AS3 we would have:


  1. private var countTime:int;

is c# we have:

  1. private int countTime;

The timer is similar to what we are used to in AS3, one difference, is in the way it fires the event:

  1. Timer timer = new Timer(1000);
  3. timer.Elapsed += new ElapsedEventHandler(TimerTick);
  4. timer.Start();
  6. void TimerTick(object o, System.EventArgs e)
  7. {
  8. //do something
  10. }

Were TimerTick is the the method it fires after the time has passed. For more info see the Timer class.

Were in AS3 we would have:


  1. var timer:Timer = new Timer(1000, 1);
  2. timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
  3. timer.start();
  4. private function onTimerComplete(e:TimerEvent):void
  5. {
  6. //do something
  7. }


One last thing we have in our countdown, is the TimeSpan. This class, makes working with dates a little bit easier than in AS3. See the full docs at: timespan

In this countdown, it simply creates a date from the number of seconds we provide. This removes the trouble of converting seconds to minutes, or hours, days, etc.

On our last line, we display the countdown:

  1. timerTextfield.GetComponent&lt;TextLink&gt; ().text = string.Format ("{0:0}:{1:00}", t.Minutes, t.Seconds);

If you want to modify a GameObject component public vars and methods from another script.

First you need your GameObject name to locate it,  using  GameObject.Find(“NameOfGameObject”), which can be assigned to a variable:

  1. GameObject myObject = GameObject.Find("NameOfGameObject");

Second you need the component name (the script name) of that game object:

  1.   myObject .GetComponent&lt;ScriptName&gt; ().somePublicVariable

To fire public methods:

  1.   myObject .GetComponent&lt;ScriptName&gt; ().methodName()

To remember, the name of the GameObject is inside () and surrounded by “”, and the name of the script is inside <>, with no quotes.

In one line, our example would look like:

  1. GameObject.Find ("CountdownTextfield").GetComponent&lt;TextLink&gt; ().text = string.Format ("{0:0}:{1:00}", t.Minutes, t.Seconds);


It does take a little bit to get used to how Unity and C# works, but it is worth the time, Unity 3D is pretty awesome.


Share this

Using JSON and actionscript 3 to display a leaderboard, back-end php and MySQL

Categories Actionscript, JSON

I have worked with XML for many years, now I had a chance to use JSON on a little pice of a project. The documentation might be confusing for many people so here is a simple easy to understand use of JSON with actionscript 3 and php, MySQL.

The idea is to list the top 10 users in a MySQL database based on their score.

Here is how the php part looks like:

  1. &lt; ?php include 'config.php'; include 'opendb.php'; $sql = "SELECT username, score FROM app_table ORDER BY score DESC LIMIT 10"; $result = mysql_query($sql); $objArray = array(); while ($row = mysql_fetch_assoc($result)) { $objArray[] = $row; } echo json_encode($objArray); include 'closedb.php'; ?&gt;

The trick is to save each result in an array $objArray[] so you will be able to properly use the JSON object in actionscript as an array.

In flash you would have to put a data grid component on the stage (ctr+f7 to open the components panel), name it myDataGrid.


  1. var serverAdress:String = "http://yourserver/"
  2. myDataGrid.columns = ["username", "score"];
  3. var request:URLRequest = new URLRequest();
  4. request.url = serverAdress + "top.php?"+Math.random();
  5. request.requestHeaders=[new URLRequestHeader("Content-Type", "application/json")];
  6. request.method=URLRequestMethod.GET;
  7. var loader:URLLoader=new URLLoader();
  8. loader.addEventListener(Event.COMPLETE, receive);
  9. function receive(e:Event):void
  10. {
  11. var myResults:Object = JSON.parse(e.target.data);
  13. for (var i:int = 0; i &lt; myResults.length; i++)
  14. {
  15. myDataGrid.addItem(myResults[i]);
  16. }
  18. }
  19. loader.load(request);

To see the top username you would do:


  1. trace(myResults[0].username);

Now I think this is a lot more simpler that dealing with XML, although XML might have it’s strong points, JSON is a lot smaller so especially when dealing with large sets of data, JSON will save bandwidth and also might save some processing time on the client (I have to test this out).

Share this

Dynamic access your xml data

Categories Actionscript

Let’s say you have this xml data in an external file data.xml:


  1. <app>
  2.   <usa>
  3.    <Alabama pic="somepic.jpg" info="some info" />
  4.    <Alaska pic="somepic.jpg" info="some info" />
  5.    <Arizona pic="somepic.jpg" info="some info" />
  6.   </usa>
  7.  </app>

If you want to access your Alaska info data in actionscript, using just the name Alaska in a variable you can do:


  1. // assuming you loaded your external xml in xmlData
  3. var country:String = "Alaska"
  5. xmlData.usa.children().(name() == country).@info
Share this