Ajax and Ajax Frameworks

I have been a developer for nearly 20 years and a web developer for about 10 years. Over the years, I have considered creating a blog to share the things I have learned (and am learning) about web design and development, but I never seemed to have the time. When I began learning about web development using Ajax and Ajax Frameworks, I decided to take the time to create this blog.

My intention for this blog is to focus primarily on Ajax Frameworks, but since web development requires knowledge of many technologies, I will occasionally write about things such as CSS, Javascript, PHP, MySQL, Flash, etc.

Lately, I have been using JQuery as my primary Ajax tool. Although I have used other Ajax Frameworks in the past (Dojo Toolkit, Yahoo! User Interface Library, Scriptaculous/Prototype), JQuery has thus far been the easiest to learn. In my first few posts I will discuss some of the JQuery Plugins that I have created. Some of these include: a plugin for Google Maps (jquery.imGoogleMaps), Form validation and submission  (jquery.imValidateForm), Page Populater (jquery.imPagePopulate), and a plugin to create lists (jquery.imList).

While I am still learning about some of the other Ajax Frameworks, I hope that what I have learned will be helpful to others. Just remember, “When you can pull the pebbles from my hand…”

Share

Loading Multiple Images using the gpUrlLoader Class

Wednesday, June 30th, 2010

I discussed the use of the gpUrlLoader Class in a previous post (see: AS3: A URLLoader Class). This class, part of my gpAS3Library, will load image, swf, text, xml, html, stylesheet, json, and sound files.

In this post, I will discuss how to use the gpUrlLoader class to load multiple images into a Flash movie. I used this technique when I created the gpFlashGallery (A free Flash/XML photo gallery).

?View Code ACTIONSCRIPT
package {
 
	import flash.display.Sprite;
	import flash.display.Loader;
	import flash.events.*;
	import com.grasshopper.utils.*;
 
	public class gpGallery extends Sprite {
                private var images_xml:XMLList;
		private var images_ar:Array = new Array();
		private var cnt:int = 0;
                private var total_images:int;
 
		public function gpGallery() {
 
		}
 
		public function init(images:XML):void {
                        images_xml = images;
                        total_images = images_xml.length();
			loadImage();
		}
 
                private function loadImage():void  {
			images_ar[cnt] = new gpUrlLoader();
			images_ar[cnt].addEventListener(Event.COMPLETE, imageLoaded);
			images_ar[cnt].init(images_xml[cnt].@thumb, 'image');
		}
 
                private function imageLoaded(e:Event):void {
			var ldr:Loader = images_ar[cnt].getImage();
                        addChild(ldr);
                        // ldr.x = 
                        // ldr.y =
			cnt++;
			if (cnt < total_images) {
				loadImage();
			} 
		}
}

I store each instance of the gpUrlLoader in an array.

?View Code ACTIONSCRIPT
images_ar[cnt] = new gpUrlLoader();

I initialize the gpUrlLoader class using a thumb attribute from an images XMLList.

?View Code ACTIONSCRIPT
images_ar[cnt].init(images_xml[cnt].@thumb, 'image');

Once the image is loaded, I call the getImage method of the gpUrlLoader class.

?View Code ACTIONSCRIPT
var ldr:Loader = images_ar[cnt].getImage();

If the count (cnt) is less than the total number of images, call the loadImage method.

?View Code ACTIONSCRIPT
if (cnt < total_images) {
	loadImage();
}

That’s it. Loading multiple images into a flash movie has never been so easy.

Share

CommentLuv badge