Sacramento, CA

Sunny 64° | 35°

Seattle, WA

Sunny 57° | 35°

Buk Life

Posts Tagged ‘Flash’

11 March 2011

Load multiple images in AS3 by storing loader information in an object

It’s easy to store images in an array, and loop through that array to access those images. The code is very clean, and easy to manage. My concept is to try and load images from an array by looping through the array, and reusing one loader method multiple times. I would instantiate a new loader instance each iteration through the loop, and then load the image. The problem, however, is by the time the image is actually loaded, the for loop is complete, and my call addChild(l) is referring to the last time Loader was instantiated, so all of the images loaded were the last one in the array.

I’ve found an elegant solution to this (in my opinion) by creating an object for each image, and to store information about the image in that object, including an instance of the loader. Let me show you.

Example


//counter to keep track of unique items in the array
var counter:Number = 0;

//base array with paths to the images
var images:Array = ["img1.jpg", "img2.jpg", "img3.jpg", "img4.jpg"];

//blank array which will be filled with objects that contain image data
var imageObjectArray = [];

for(var i:uint = 0; i < images.length; i++) {

	//create blank object with appropriate properties
	var imgMeta:Object = {imgPath: null, holder:null, loaderInst: null};

	//push the object into imageObjectArray so we can access it later
	imgObjectArray.push(imgMeta);

	//set the properties we know
	imgMeta.imgPath = images[i];
	var imgHolder:Sprite = new Sprite();
	imgMeta.holder = imgHolder;	

	//load the image here
	var l:loader = new Loader();
	l.contentLoaderInfo.addEventListener(Event.COMPLETE, onDoneLoading);
	l.load(new URLRequest(imgMeta.imgPath));
}

//function called when each image is done loading
function onLoadComplete(e:Event) {

	//use counter here to make sure we're getting the correct imageObject
	//we need to call each unique loaderInst here, so each image is unique
	addChild(imgObjectArray[counter].loaderInst);
	counter++;
}

This of course can be classed out and abstracted, but the basic principal here is being able to reuse the loader code each time through the for loop, and displaying each unique image when it’s done being loaded.

An additional benefit to this is being able to use the object again anywhere in your code, since all the information for all of the images is stored in imgObjectArray.

Tags: , ,
2 It’s easy to store images in an array, and loop through that array to access those images. The code is very clean, and easy to manage. My concept is to try and load images from an array by looping through the array, and reusing one loader method multiple times. I would instantiate a new loader [...] Matt Aebersold,Senior Interactive Developer

March 11th, 2011 at 04:25 PM
Posted By: matt.aebersold in Development

11 May 2010

Flash SEO

Flash has a strong reputation for creating visually stunning websites, and rightfully so. Just head over to The FWA to see some of the best flash-based websites ever designed. As good as flash is at delivering rich media to the web, there are some serious downsides to consider.

One of the largest drawbacks to flash content is it’s relative invisibility to search engines and accessibility programs. The criticism is true when talking about Flash as a closed platform. The code written is compiled into a SWF, and then embedded online. This makes searching an indexing flash content extremely difficult for most search engines. Accessing Flash content is also a problem for screen readers and other accessibility programs.

These issues, combined with the popularity of the Apple devices, create a lot of hesitancy for companies to fully embrace Flash content in their projects and sirs. I’m going to talk about a few key principals that will help Flash gain visibility and accessibility across multiple platforms, and at the same time make Flash content easier to update and maintain.

Does it need to be Flash?

The first step, of course, is to figure out what content needs to be in Flash, and what does not. There’s no point to constructing a site using flash if the same design can be achieved using more open, standards-compliant code. Once the decisions have been made as to what content will be built in Flash, than it’s time to start thinking along the same lines as proponents of web standards.

Use the Principals of Web Standards

The primary rule in web development today is the separation of content from presentation. The same principal can be applied to Flash projects. Separating the content from the design means updating and maintaining the Flash site will be much easier if the code doesn’t need to be recompiled and edited every time a change needs to be made. Making things like the navigation, links, and photos flexible and external are all great steps to create clean, smart, and flexible projects.

Smart Degradation

If the Flash content and design are properly separated, than re-purposing the content is extremely easy. If the content is in XML format, it can be applied to an XML site-map which will help search engines index the site’s content much easier. In addition, there are browser and platform detection scripts which could allow you to display the XML content in regular HTML format if the browser or device isn’t compatible with Flash. (iPad anyone?) You can also detect older browsers and Flash players. Content can then be delivered in the most efficient way possible to all users.

For example, head over to the BKWLD site on an iPad or iPhone, and you will see that the features on the homepage are still visible and interactive. This helps serve the most people possible the site’s content, no matter what environment they are using to visit the site.

Hybrids

There is also the option of creating hybrid sites, which are very popular because they combine flash elements with standard HTML markup. This allows the user to have a rich experience, as well as giving search engines easy access to the site’s content. Making use of flashvars and XML/JSON add to the flexibility of the site by allowing Flash to communicate directly with the rest of the site.

SWFObject & Deep Linking

Making use of programs like SWFAddress and SWFObject allow the Flash content to be more transparent and visible to search engines. SWFAddress will create a specific URL for each page in a full-browser Flash experience. Knowing what section the user is on, and showing that section in the browser’s address bar allow search engines to look at specific pages, and create extremely accurate analytical reports.

SWFObject is a way to create valid code though the W3C Validation tools. Also, SWFObject has the ability to replace Flash content with a static image, which maintains the visual design if the user doesn’t have flash enabled.

Conclusion

It’s ultimately about choosing the right tool for the right project. Flash has many advantages, which need to be carefully weighed against the areas in which Flash falls short. The ideas described here can certainly help Flash communicate better with browsers, search engines, analytical tools, and accessibility programs.

6 July 2009

Copy paste between Fireworks and Flash

I don’t often batch import layered files (PSD, PNG) into Flash or even copy graphics into it.  But what I DO find really handy is copying text between the apps.  This worked in CS3 but it’s gotten better (more accurate) in CS4.  You can copy a whole group in and the font, size, and color are all maintained (or close enough, you usually have to nudge line height).  This saves tons of time when you’re populating a whole FLA from a text heavy design while keeping the text editable for the inevitable copy change.  Notice in this video how I can bring in multiple text boxes at a time.

29 October 2007

Bitrate calculator

My doppleganger posted this bitrate calculator for making FLVs. We should refer to this in the future for telling people what to set their compression settings to, instead of my usual “uhhh 400kbs?”

Tags:
0 My doppleganger posted this bitrate calculator for making FLVs. We should refer to this in the future for telling people what to set their compression settings to, instead of my usual “uhhh 400kbs?” Robert Reinhard,CTO

October 29th, 2007 at 03:57 PM
Posted By: Robert Reinhard in Development

25 October 2007

Goodbye onReleaseOutside

Noticed today that there is no onReleaseOutside in AS3 and events don’t fire when your mouse isn’t on the displayObject. Senocular, as usual, has the answer.

Tags:
0 Noticed today that there is no onReleaseOutside in AS3 and events don’t fire when your mouse isn’t on the displayObject. Senocular, as usual, has the answer. Robert Reinhard,CTO

October 25th, 2007 at 11:07 AM
Posted By: Robert Reinhard in Development

24 October 2007

Flash 9 components, let me skin you!

Slider ARGH!I was trying to save time and increase functionality by making use of the Flash 9 components. I’m really not a component person, never used them in old version of flash. But I’d gone to a presentation at the local user group where I “learned” that the new components were hella easy to use and, most importantly, skin. Well using them, yes, that’s easy and can really speed up a prototype. Tonight I tried to skin the slider component. Every bit I replaced was scaled wrong, as if it were being forced to fit within the size of the original slider elements. So if the grabber thing was 10×10, i couldn’t put a new grabber that was 50×50 in it’s place or it would scale down. Apparently the only scale you can change is the length of the slider. Bummer.

Tags:

2 October 2007

Flash Player 10

The multi columned text will really help text based flash. It’d be cool if they built in some easy hooks to dynamically resize the page. But the really amazing thing is that 3d stuff. Holy shit! Man, this woulda helped the BKWLD.com site out TREMENDOUSLY. This is really gonna lead to some exciting APIs. (link courtesy of Jeff)

Tags: ,