Creating Your Own Panels

Flash comes with a lot of panels, but you might not need or want every one. No worriesyou can create your own panels, which isn't really new, but now you can use the MMExecute() function, which will execute any JSFL command within the authoring environment. When the Flash file (.swf) has been created, you can drop it in the WindowSWF directory in the Flash 8 directory and restart the Flash authoring environment. Then you can find it under Windows, Other Panels in the menu bar.

The basic layout of the MMExecute() method is as follows:


The difficult aspect of using the MMExecute() method is that the command must be passed as a string, but the dynamic content cannot. For instance, if you were to send the current date and time to the Output panel, it would look something like this:

 MMExecute("fl.trace('" + new Date() + "');"); 

Notice the abundance of quotation marks to make it work right, just something to keep in mind when using the MMExecute() function.

Now that you have seen the basic usage of the function we are going to use to create our first panel, let's get started.


Create a new Flash document.


Set its dimensions to 200x100.


Drag three components onto the stage and place them as follows:

  • TextInput component Set its width to about 180, give it an instance name of myText_ti, and place it in the top half of the stage.

  • Button component Give it an instance name of myButton_butn, set its label parameter to Send, change its width to about 48, and place it in the bottom left of the stage.

  • ComboBox component Give it an instance name of myCombo_combo, place it at the bottom right of the stage, and give it two labels:

 "to output" "to alert" 

Your stage should now look like Figure 27.11.

Figure 27.11. Use components to quickly create custom panels.


Create a new layer called actions.


Open the Actions panel in the first frame of the Actions layer and place this code in:

 //event listener object var clickListen:Object = new Object(); //create the event = function(){     if(myCombo.value == "to output"){         MMExecute("fl.trace('" + myText.text + "');");     }else{         MMExecute("alert('"+myText.text + "');");     } } //add the listener myButton.addEventListener("click",clickListen); 

The preceding code first creates an event listener object. Then it creates an event callback method for that object that checks where the string from the TextInput component is supposed to goeither to the Output panel or to an alert message. Then finally we add the event listener to the Button component.


Now save the file as Send Out.fla and test the movie.


Copy the .swf file created to the WindowSWF directory of the Flash 8 first-run directory and restart Flash.


When Flash has been restarted, choose Window, Other Panels, Send Out. Now you have the capability to send messages to the Output panel as well as in the form of alert messages, as in Figure 27.12.

Figure 27.12. You can see that the panel created can send messages both to the Output panel and as an alert message.

This example does not have the most practical uses, but it does show what is possible by combining Flash developing, JSFL, and the MMExecute() function. As you become more comfortable with JSFL, you will begin to create many of your own panels.

But panels are not the end of customizing the authoring environment of Flash. You can also create your own tools with JSFL and place them in the toolbar.

Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319 © 2008-2017.
If you may any questions please contact us: