Archive for June, 2007

actionscript 3, pushing asynchronous data through multipule classes

So a couple of weeks ago a friend and I were talking about the now hardship of as3 and retrieving class properties when building app.

Ok, lets say in Class A I load an image.

Class B – I am calling two copies of Class A to make two loaded images. make Objects in Class B. If I try to space them equally with classAobj2.x = classAobj1.width + 5,

I get “5″. That is a problem.
(”But Josh, you shouldn’t have a ton of loader objects.” I know I should make a iterator or something but I’m not there yet)

devonair on gotoandlearn.com forums told me about how to pass that var buy creating a custom event. It works but it’s a waste of time to do that for every time you need it. The same friend I was talking to gave me the great “catch all” for passing var through certain events.

See here:

[as]package events
{
import flash.events.Event;

public class GenericEvent extends Event {
public var _data:*;

function GenericEvent (evt:String) {
super(evt);
}

}
}[/as]

So I tested it and it’s nice I can pass a crap load of stuff because it’s an Object i.e.: generic._data = ({width: load.width, height: load.height});

So let’s do that example:

We are going to make three classes, build it like this:

  • /root
  • -customEventExample.as
  • /events
    • -GenericEvent.as
  • /display
    • Loading.as

Let’s start w/ Loading.as because we already have the GenericEvent.

[as]

package display
{
import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import events.GenericEvent;

public class Loading extends Sprite
{

private var load:Loader;

public function Loading()
{
load = new Loader();
load.load(new URLRequest(”http://www.kornitaly.com/Discografia/Korn.jpg”));
addChild(load);
load.contentLoaderInfo.addEventListener(Event.COMPLETE, loadHandler);

}
private function loadHandler(event:Event):void
{
var generic:GenericEvent = new GenericEvent(Event.COMPLETE);
generic._data = ({width: load.width, height: load.height});
dispatchEvent(generic);
}
}
}[/as]

Now the main class file customEventExample:

[as]

package {
import flash.display.Sprite;
import flash.display.SimpleButton;
import flash.display.Shape;
import flash.events.MouseEvent;
import events.GenericEvent;
import display.Loading

import flash.events.Event;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
[SWF(width="450", height="450")]
public class customEventExample extends Sprite
{
private var _width:int;
private var image:Loading;
private var image2:Loading;

public function customEventExample()
{
image = new Loading();
image2 = new Loading();
addChild(image);
addChild(image2);

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.EXACT_FIT;

image.addEventListener(Event.COMPLETE, clickHandler);
image.addEventListener(Event.COMPLETE, clickHandler);
}

public function clickHandler(event:GenericEvent):void
{

_width = event._data.width

trace(_width);
if(image2)
{
image2.x = _width + 5;
}

}
}
}
[/as]

dowload zip

I think this is called a proxy of some sort. I’m still learning Design Patterns. Also I’ve learned you can achieve this w/ the DataEvent.

1 comment June 11th, 2007

Apollo is now Adobe Intergrated Runtime Flex 3 Moxie is beta to the public

Wow, Apollo is now beta. I’m going to still call it Apollo. I like it better then that stale name it is now. I like the acronym but not the full name.

Also Flex 3 beta is out!!! Get it now.

Flex builder 3 MOXIE

Flex SDK

Apollo beta 1

Apollo SDK

HAPPY CODING

Add comment June 11th, 2007

Pumpkins Live!!!

Smashing pumpkinsI heard the new Smashing Pumpkins single for Zeitgeist. It’s nice, I can’t get it out of my head. Catchy, rockin’, w/ a lite punk flavor. I can’t wait to here the new album. And pay $100 for tickets to the concert… maybe.

P.S. I got some flex and as3 stuff going on to share in a few days.

Add comment June 8th, 2007

Filter Data with ArrayCollection

After watching a Lynda.com tutorial realized I didn’t have to do as much work to filter data.

the filterFunction is a public property of the ICollectionView witch is the class that the ArrayCollection extends from.

So this function/method is accessible to a ArrayCollection.
[as]

< ?xml version="1.0" encoding="utf-8"?>

< ![CDATA[
import mx.collections.*;

private var collectionArray:Array;
[Bindable]
private var collectionData:ArrayCollection;

private function init():void
{
collectionArray = [{first: 'Dave', last: 'Matthews'},
{first: 'Amy', last: 'Grant'},
{first: 'Bilbo', last: 'Baggins'},
{first: 'Jessica', last: 'Tandy'},
{first: 'Paris', last: 'Hilton'}];
collectionData = new ArrayCollection(collectionArray);
}

public function filter():void {

//pass my filter function to the method w/ no ()
// you must also refresh it
collectionData.filterFunction = filterFirst;
collectionData.refresh();

}
// function see's if the searchField's text is equal to the "first" object of the collectionData

//if true it show results, if false it shows nothing
private function filterFirst(item:Object):Boolean
{
return (item.first == searchField.text)

}
]]>
[/as]

Problems w/ this:

  1. I have not found a way to match with just typing in “Da” and it is case-sensitive
  2. When you type in a non-matching string it will not reset to beginning state. (I’m sleepy so maybe that’s why I can’t figure it out.)

3 comments June 6th, 2007


    Blog Calendar

    June 2007
    M T W T F S S
    « May   Jul »
     123
    45678910
    11121314151617
    18192021222324
    252627282930  

    Posts by Month

    Posts by Category