Reducing Errors in Component Creation

Now we will discuss some common mistakes you can make during the development process of components. Be sure to keep these ideas fresh in your mind while creating a component, as they are very annoying to correct when you are done.

By far the most aggravating problem you will encounter is making typos. Although you cannot fully prevent typos, you can try to avoid certain common mistakes. Firstly, the name of component's ActionScript class is more likely to be misspelled than anything else. Since you have to type it so many times, your fingers can become fatigued from doing the same thing. Therefore, it is best to go through each prototyped method you have written and make sure the name of the class is spelled correctly.

The most important step in the component creation process is setting up the relationship between the ActionScript class and component movie clip. You therefore need to double-check that this association has been set up correctly. Open the Linkage Properties dialog box of the component movie clip and check the spelling of the linkage name. Also check that you gave the movie clip a linkage name in the first place. Next, look in the actions of the component to confirm that the inheritance is set up correctly. In general, it should look like this:

         Object.registerClass ("ComponentLinkage", ComponentClass);         ComponentClass.prototype = new MovieClip (); 

Finally, the last place to look for small faults is in the Component Definition dialog box. In it, recheck the names of the variables you are using for the parameters, and make sure those are the identifiers you use in your code. Often you will change and remove parameters from the component, and you must make sure that your code reflects all of those changes.

When Changing Parameters

The last thing you should keep an eye on is very counterintuitive, but it has caused developers the greatest distress. It has to do with the small irregularities in how Flash deals with the parameters of the component. When you drag a component to the stage, its parameters are changed to variables, as we saw in Chapter 10, but those variables stay local. Meaning, the only way to change them is to open the instance's Parameters panel and change those values. This may seem like common sense, but imagine this situation: You have an instance of your component on the stage while in middevelopment because you need it for testing. During this time, you change the component's default values, yet the instance of the component on the stage retains the same values as before. As a general rule, whenever you change the component's definition, you should delete all the instances off the stage, and redrag them to them to where you want.

Another quirk occurs when you change a component's definition while instances of the component are on the stage. If you change the component's definition in certain ways, such as adding a parameter or changing the name of a parameter, then the changes to the definition will not be saved. After closing the Component Definition dialog box and saving, the parameters will resort back to their values from before. Indeed, this is quite a strange happening, and it is probably a bug in Flash MX. So, from now on, delete all instances of a component off the stage if you are going to change its component definition, and replace the instances when you are done, or else the changes will not stay.




The Hidden Power of Flash Components
The Hidden Power of Flash Components
ISBN: 0782142109
EAN: 2147483647
Year: 2002
Pages: 111

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net