Archive for the ‘as3’ Category

Filter Data with ArrayCollection

Jun
6

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.)

Actionscript 3 Clouds

May
8

I made my own rendition to AS3:Cookbook example of Perlin Noise, an effect created for Tron believe it or not.

[as]

package {
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
import flash.geom.Point;
import flash.display.BitmapDataChannel;

public class Clouds extends Sprite
{
private var _bitmap:BitmapData;
private var _xoffset:int = 0;
private var _w:Number
private var _h:Number

public function Clouds(w:Number, h:Number)
{
_w = w;
_h = h;
_bitmap = new BitmapData(_w, _h, true, 0xffFFFFFF);
var image:Bitmap = new Bitmap(_bitmap);
image.x = image.y = 0;
addChild(image);
addEventListener(Event.ENTER_FRAME, onEnterFrame);

}

public function onEnterFrame(event:Event):void
{
_xoffset++;
var point:Point = new Point(_xoffset, 0);

_bitmap.perlinNoise(200, 100, 2, 1000, true, true, 8, true, [point, point]);
}
}
}

[/as]