Components
Component Handlers
There is easy way to use data which are available from the user working with the components.
Let's make a small example
- Write the dynamic text "FLASH" or any. Give it an instance name flashtext
- Create a list box as we've done before. In Parameters tab of Properties Inspector type color names as labels, for example "red, blue, black" and so on
- Give this list box an instance name colorpicker
- For values enter 1, 2, 3 and so on.
- For the Change Handler line enter flashcolor
- Enter the following code in the frame of the timeline
function flashcolor() { thecolor = _root.colorpicker.getSelectedItem().data; switch(thecolor){ case 1: flashtext.TextColor=0x0000ff; break; case 2: flashtext.TextColor = 0x000000; break; case 3: flashtext.TextColor = 0xFF0000; break; case 4: flashtext.TextColor = 0xFFFF00; break; case 5: flashtext.TextColor = 0x00aa00; break; case 6: flashtext.TextColor = 0x888800; break; default: flashtext.TextColor=0x999999; } }When item is selected from the list – the Change event handler is calling the function flashcolor(). Inside this function the selected data are extracted. For example we picked "blue" item. It corresponds to "1" data.After the data is known the switch structure is used to make a decision what color to assign to the text.
Pay attention to switch syntax. It must be exactly like that – colon after each case and breakstatement. Without break switch will find the matching value of the parameters and execute all following cases.
- Test the movie. Color of the text should change when list item is picked. Adjust color values to labels. Remember RGB notation – first two digits after 0x are for red, next 2 for green and last 2 for blue. Values are hexadecimal and change from 0 to F
Look at the ActionScript Flash help to find more methods and properties of the components. You will find them under FcomboBox, FcheckBox and similar names