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.

This entry was posted in ActionScript, Components, Flash. Bookmark the permalink.

4 Responses to MinimalConfigurator.getCompById

  1. That’s a very nice improvement!

    I thought of a feature you might consider. How about a way to specify a component derivative class in the XML? Perhaps something like this:

    In that case, it would also be nice to be able to specify fields specific to the derivative class. You could simply try to add any extra attributes:

    If MyPushButton had a public “clickSound” variable, you would set it.

    Anyhow, just a thought. Thanks for your continued work on Minimal Comps!

    • The comments system ate my examples. 🙁 Here they are again with parenthesis instead:

      “Perhaps something like this:”
      (PushButton class=”MyPushButton” … /)

      “You could simply try to add any extra attributes:”
      (PushButton class=”MyPushButton” clickSound=”click.mp3″ … /)

  2. JLM says:

    I was experimenting with similar in openpyro and away3d, I will mention a few things you may not have tried? for comboboxes the dataprovider was a string with commas, also had some other rich types in the properties strings, rather a hacky use of underscores etc.. , and skinning was via xml, and started looking at several passes so I could wire up listeners or override materials, so for instance I could overide a collada models material with a video and then set another material as a start stop button, and wire up the listener of the combobox to change something but all done really generic just with xml that is loaded or embedded, actually managed to get the openpyro component xml loading in and populating an away3d material and also used them for changing the focus etc… The away3d stuff is closed unfortunately, the openpyro xml parser I keep meaning to open as it’s now fairly functional, the stuff works in as3 but yet to get round to haxe port so not yet released. All really powerful stuff but I do hate trying to get xml parsing right, keep thinking maybe yaml.

    I was wondering do your components have any layout stuff like openpyro does, openpyro has some skinning but not really ideal approach but it mixes well with normal flash, and does seem light and flexible, I think there is still a flex alternate hole that needs filling. Recently I have looked at Physaxe and thinking you could use a physics engine in component layout… or not 🙂

    I keep hoping you will get into haXe, as it would be very interesting to see these via jeash ( html5 javascript), and I am sure the process would make you rethink aspects.

    Cheers

    ;j

    • keith says:

      yeah, there’s lots more stuff that *could* be done. Trying to keep it light and minimal, rather than being huge and complex. But I’m sure I’ll consider adding features here and there.

Leave a Reply