BIT-101 [2003-2017]

MinimalConfigurator.getCompById


Just added a new feature, as suggested by Karim in the previous post. This saves a hash of all components that have id attributes, and then allows you to find any component by its id. Here’s an example:

[code lang=“as3″]package
{
import com.bit101.components.*;
import com.bit101.utils.MinimalConfigurator;

import flash.display.Sprite;
import flash.events.Event;

public class Playground extends Sprite
{
private var config:MinimalConfigurator;

public function Playground()
{
Component.initStage(stage);

var xml:XML =

;

config = new MinimalConfigurator(this);
config.parseXML(xml);
}

public function onClick(event:Event):void
{
var btn:PushButton = config.getCompById(“foo”) as PushButton;
btn.label = “goodbye”;
trace(btn.name); // foo
}
}
}[/code]

Also, it maps the id to the component’s native name property, in case that might be useful.

All in all, this allows you to access multiple components without having to make a bunch of public variables.

« Previous Post
Next Post »