Basic ArrayBinder class for CS3 and Actionscript projects

I've written a class that can help separate the view from the model in Flash projects.  It is by no means equivilent to data binding available in Flex (and far from it!) but I've used bind in the title because it does effectively bind the values held in an ArrayBinder instance to object properties that have subscribed to refer to those values.   The specific use that I have in mind for ArrayBinder is in assisting with localising interfaces for applications that are developed in Flash CS3.  Here's how it works;

Create a simple array:


var dataArr:Array = new Array();
dataArr[0] = "Sample title for my Flash App";
dataArr[1] = "Sample textfield value";
datArr[2] = "This is a button label";

Assign the simple array to an ArrayBinder instance:


var myArrBind:ArrayBinder = new ArrayBinder(myArr);

Register class types and their property names that will be used in the ArrayBinder instance:


myArrBind.addReceiverType(TextField, "text");
myArrBind.addReceiverType(Button, "labelTxt");

Register stage instances and the index position of a value to subscribe to:


myArrBind.addReceiverInstance(title_text,0);
myArrBind.addReceiverInstance(sample_txt,1);
myArrBind.addReceiverInstance(myButton,2);

The code so far will automatically populate a basic interface consisting of two textfields and a button. The real benefit of this approach occurs when you have a more elaborate interface with a lot more button labels, textfields, textAreas, etc. When I want to change the interface text to another language, all I have to do is change the datasource that the ArrayBinder instance is using;


myArrBind.changeArray = anotherLangArr;

I can also alter specific values without changing the entire datasource;


myArrBind.updateArrayIndexOf(2, "This is my NEW button label");

Here is a link to the Class file.

Tags: ,

This entry was posted on Sunday, March 9th, 2008 at 7:21 pm and is filed under Actionscript. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

 

2 Responses to “Basic ArrayBinder class for CS3 and Actionscript projects”

  1. Actionscript Classes » ArrayBinder for Flash CS3 Says:

    […] http://fboyle.com/blog/?p=10  […]

  2. Flash CS3とアクションプロジェクト向けベーシックのArrayBinderクラス | DigiTechLog Dot Com Says:

    […] 次のリンクでソースコードをダウンロードできます。もっと詳しい情報はここに参照できます。 メインコンテンツEND ■ (No Ratings Yet)  Loading … […]

Leave a Reply

You must be logged in to post a comment.