AS: MAIN, like sex with a n00b; as a very wise man has said
WHY!?
First of all, WHY bother with components, when you can have fancy MC's?
Because sometimes you JUST cant be bothered to draw. :P Not only that, but components have QUITE useful Stuff.
lol Wut will i learn?
Im going to go with a few components, comboBoxes, trees, and datagrids. In my opinion the most powerful/useful. Also, a bit of skinning and stuff.
INTRO
Whenever you hear "Components", you probably go all like "LOLWTFBBQ!!??11one". But no, Components are one of the biggest tools that flash can offer for you. I recently have been trying them out, and they are QUITE powerful for anything. ;) Most people dont even know how to use the components, though. Its NOT that simple.
Skinning Components
Firstly, ill begin with SKinning components. Skinning? not bbq. Its changing a components color. Like, have an example:
_global.style.setStyle("themeColor","haloG
reen");
What is ThemeColor?
Its the property of the components that we want to change.
halogreen? bbq?
No, not bbq you silly person. HaloGreen is the template of the components. The default one, Aside from haloGreen, there is haloBlue, and haloOrange. Try it out. ;)
<Note>
Any of the following will also work:
_global.style.setStyle("themeColor",0xFF00
00);// thats red
</Note>
basically, we are changing the STYLE of the global components. Which is EVERY silly thing you have on the flash.
You can, however, change styles to any single component. Like this:
component_instance.setStyle("themeColor","
haloBlue");
Which will just affect one component. Easy, huh?
Now, lets go a bit more detailed onto components themselves, k? k.
Lets start off with a comboBox,k ? Most of the components are used the same. I'll work with
arrays.
//creating an array
var people:Array = new Array();
//inserting stuff into the array
people.push({data:"",label:"Choose a person"});
people.push({data:"D", label:"Diego"});
people.push({data:"C",label:"Chad"});
people.push({data:"J",label:"Jay"});
// I will keep using this array from now on for every other component, so, dont lose it k.
The above just creates the array, now, assumming you named the comboBox "people_cbx", without the quotes. (CBX = comboBox).
people_cbx.dataProvider = people;
//setting size:
people_cbx.setSize(200);
wtf? Well, you see... dataProvider is a function (i believe), which provides the component with the data of something else. Its used on MOST components. setSize is used only for components, you dont use _width or _height for them, it just stretches them out. THAT ISIMPORTANT. Now your comboBox should be working. ;)
You can also make the combobox editable by just... going:
people_cbx.editable=true;
// get it?
DATAGRIDS.
Literally one of the most powerful tools that flash can lend you, really! XD
Now, drag a datagrid onto the stage.
give this code to the frame:
//track if any grid rows have been selected
var SelectedGrid:Boolean;
var GridRowSelected:Number;
//I'll just use the same ol people array.
//Assuming you instanced the grid "people_grid".
people_grid.dataProvider = people;
people_grid.setSize(300,100);
//DataGrids can also be editable:
people_grid.editable = true;
Test your movie out. The dataGrid will put everything, with two columns. Data, and Name. Which i provided in the people array. Its not too complicated, is it? :P Lets move on.
Now, lets see, a TREE component?
Tree Components can be QUITE useful. For keeping data ordered and stuff. Mostly for XML, i guess. So lets say, we CREATE our own XML file with Flash itself, like..
var stuff_xml:XML = new XML();
//creating elements
stuff_node = stuff_xml.createElement("node");
lol_node = stuff_node.cloneNode(true);
wtf_node = stuff_node.cloneNode(true);
//adding attributes
stuff_node.attributes.label = "STUFF";
lol_node.attributes.label = "LOL?";
wtf_node.attributes.label = "WTF!!1";
//placing elements on the Tree
stuff_xml.appendChild(stuff_node);
lol_node.appendChild(wtf_node);
/*placing it on the tree,
Assuming youve called it stuff_tree*/
stuff_tree.dataProvider = stuff_xml;
Test the movie. ;) Dont worry about the nodes and stuff, thats just an example on WHAT can you use a tree for, and howd it look. Nice, doesnt it?
Yes, i am learning XML (well, a little), so i wanted to try it out.
OTHER USEFUL STUFF TO KNOW ABOUT FLASH/COMPONENTS
You CANT change a component's size with _height or _width. That stretches them. You use setSize.
You MOVE a component using stuff.move(x,y);
for buttons, and most stuff, you use the "label" property. Thing_btn.label = "LOL";
For Grids, you can also use addColumn(columnName); spaceColumnsEqually(); and removeColumn(columnName);
most are self explanatory.
Skinning/setting styles is pwn. ;)
K, i guess thats all for this one. :) Pretty useless/stupid.
I came out with all of this after trying/testing/erroring most components and inspectionating around the *.as files that flash has. ;) Good luck silly person.