all groups > flash actionscript > june 2006 >
You're in the

flash actionscript

group:

Determining the v2 Component Type


Determining the v2 Component Type gurthWERM
6/30/2006 8:10:33 PM
flash actionscript:
I'd like to run a looping switch routine to check all of my components and
execute different scripts depending on what type of component each is. But I
don't know how to check to see if something is a ComboBox, CheckBox, etc.

Is there a way to check for the component class?

Thanks.

JW
Re: Determining the v2 Component Type eddymilner
6/30/2006 11:22:45 PM
well , yes and no ... if you have on stage few components , you have give them
instanece name ....


tray this one :

drag to the Stage button componet and name it : button_a
drag another button and name it :button_23
drag combobox and nam it:combobox_1

so drag as many components you want on the stage and name it as component
class and separte it with 'underscore' :

combobox = combobox_32
datagrid = datagrid_2

etc.....

and put this script :


[b]
for (var i = -40000; i<0; i++) {
if (_level0.getInstanceAtDepth(i) ne undefined) {
var search:String = new String(_level0.getInstanceAtDepth(i));
trace(search.slice(search.indexOf('.', 1)+1, search.indexOf('_', 1)));
}
}
[/b]

tell me what you think about that !

Re: Determining the v2 Component Type NSurveyor
7/1/2006 1:31:09 AM
I've got two ideas... (haven't checked them thoroughly though)

//METHOD 1
import mx.controls.*;
import mx.containers.*;

//Determine what kind of component mystery_mc is:
handleComponent(mystery_mc);

function handleComponent(x) {
switch (x.__proto__) {
case Accordion.prototype :
trace('Accordion');
break;
case Alert.prototype :
trace('Alert');
break;
case Button.prototype :
trace('Button');
break;
case CheckBox.prototype :
trace('CheckBox');
break;
case ComboBox.prototype :
trace('ComboBox');
break;
case DataGrid.prototype :
trace('DataGrid');
break;
case DateChooser.prototype :
trace('DateChooser');
break;
case DateField.prototype :
trace('DateField');
break;
case Label.prototype :
trace('Label');
break;
case List.prototype :
trace('List');
break;
case Loader.prototype :
trace('Loader');
break;
case Menu.prototype :
trace('Menu');
break;
case MenuBar.prototype :
trace('MenuBar');
break;
case NumericStepper.prototype :
trace('NumericStepper');
break;
case ProgressBar.prototype :
trace('ProgressBar');
break;
case RadioButton.prototype :
trace('RadioButton');
break;
case ScrollPane.prototype :
trace('ScrollPane');
break;
case TextArea.prototype :
trace('TextArea');
break;
case TextInput.prototype :
trace('TextInput');
break;
case Tree.prototype :
trace('Tree');
break;
case UIScrollBar.prototype :
trace('UIScrollBar');
break;
case Window.prototype :
trace('Window');
break;
default :
trace(null);
break;
}
}

//METHOD 2
import mx.controls.*;
import mx.containers.*;

//Determine what kind of component mystery_mc is:
handleComponent(mystery_mc);

function handleComponent(x) {
if (x instanceof Accordion) {
trace('Accordion');
} else if (x instanceof Alert) {
trace('Alert');
} else if (x instanceof Button) {
trace('Button');
} else if (x instanceof CheckBox) {
trace('CheckBox');
} else if (x instanceof ComboBox) {
trace('ComboBox');
} else if (x instanceof DataGrid) {
trace('DataGrid');
} else if (x instanceof DateChooser) {
trace('DateChooser');
} else if (x instanceof DateField) {
trace('DateField');
} else if (x instanceof Label) {
trace('Label');
} else if (x instanceof List) {
trace('List');
} else if (x instanceof Loader) {
trace('Loader');
} else if (x instanceof Menu) {
trace('Menu');
} else if (x instanceof MenuBar) {
trace('MenuBar');
} else if (x instanceof NumericStepper) {
trace('NumericStepper');
} else if (x instanceof ProgressBar) {
trace('ProgressBar');
} else if (x instanceof RadioButton) {
trace('RadioButton');
} else if (x instanceof ScrollPane) {
trace('ScrollPane');
} else if (x instanceof TextArea) {
trace('TextArea');
} else if (x instanceof TextInput) {
trace('TextInput');
} else if (x instanceof Tree) {
trace('Tree');
} else if (x instanceof UIScrollBar) {
trace('UIScrollBar');
} else if (x instanceof Window) {
trace('Window');
} else {
trace(null);
}
}
Re: Determining the v2 Component Type eddymilner
7/1/2006 4:46:48 AM
Re: Determining the v2 Component Type NSurveyor
7/20/2006 2:36:14 PM
AddThis Social Bookmark Button