|
Comments
|
Today's Top SOA Links
FreeHand It's All in the Object
Reusable power is always a plus
By: Charles E. Brown
Apr. 7, 2004 12:00 AM
Approximately 10 years ago a new word started to appear in programming circles: objects. The theory was that little bits of code, doing a specialized job, could be prewritten and plugged into existing code as needed. Several years later a programming language called C++ was introduced. This gave the programmer an entire library of prewritten code called class files. Each class file had one specific task assigned to it and could be plugged into any project easily as needed. This saved programmers incredible amounts of programming and debugging. Today, the word object is used by nearly every program, including Fireworks. In this article, we will examine what objects mean in Fireworks and how they can save you time and work. We will use very simple examples to illustrate the concepts. However, you will easily be able to apply these same concepts to more complex scenarios. For purposes of understanding, we are also going to use some non-Macromedia terminology. Begin by drawing a simple circle on your canvas. You can fill it in with any color you want. Once finished, select Modify > Convert to Symbol (or press the F8 key). You can give it any name you want. For example, call it myCircle and select the option to make it into a Graphic. Whether you realize it or not, you just created an object. Take a look in the Library panel by selecting it in Panels (see Image I). Think of this as a template that can be used to create other objects. The Library panel is handy in that it shows us what the object looks like and, in the bottom window, shows us the name and the type of object it is. For example purposes, delete the original circle on the canvas. Let's assume our design needs four circles, one in each corner. All we need to do is drag the circle, using either the graphic or the name, to each of the four corners of our canvas (see Image II). Believe it or not, you just had your first lesson in object-oriented design. Using the template in the library, you created four new objects on the canvas. In object-oriented programming (or OOP) parlance, we would say that we created instances of the object. Each one is a duplicate of the original. This has already saved us a lot of work because we did not have to redraw the circle four separate times. But what happens if we need all of the circles to be a different color? We can now double-click on one of the circles. This will take us to a symbol-editing canvas (you can also access the edit area by double-clicking on the symbol in the Library panel). Change the color to a different color and select the Done button, located at the top of the canvas. All the objects change to whatever color you selected. Here lies the second benefit of objects: you can change the object's attributes (color, shape, etc.) in one place and all of the objects will automatically conform to it. What happens, however, if we need to set one of the objects to a different attribute? For instance, let's say we want it to be a different color. Select the object and then select Modify > Symbol > Break Apart. The symbol you broke off is no longer attached to the symbol in the library and can have any of its attributes changed without affecting the other instances. Unfortunately, this also keeps the symbol from being changed from the library if you need to do so. Preparing Your Objects for JavaScript Many times we need to reference the objects with JavaScript. To do that, each instance must have a unique name. This is where I am going to depart from Fireworks terminology a bit. Click on the symbol and, in the Property inspector, name the object in the Symbol field. Once again, in object-oriented parlance, we call these names object references. JavaScript, like most languages today, is case sensitive. Because of that, your object references should conform to the following naming conventions.
Using Your Objects Elsewhere What happens if we want to use our objects, or symbols, on different canvases? Fireworks allows you to export and import your objects between different projects. Using the Library panel, open the Options menu and select Export Symbols. You will be taken to a box that shows you all of the symbols in the present project (see Image III). Here you can select the symbols you want to export. Once you've done that, select Export. After you select the folder you want to save your objects into it and select OK; they will be saved to an external PNG file. If you now want to import your objects into another project, open the Library panel in the new project and select Import Symbols... Once you maneuver to the folder that contains your symbol, select OK. You will be taken to a box that looks nearly identical to the one you saw when you exported. (Note: The figures shown here were created with Fireworks MX 2004. The screens in Fireworks MX look a little different but they have identical functions.) Select Import. Your symbols should now be in the Library panel, as they were in the previous project. Building Libraries This is the same box you saw when you just imported. Once again, if you select the bullet object you want, and click Import, that symbol will end up in the Library panel. If you had selected Edit > Libraries > Other..., you would have been taken to the object libraries you exported a few moments ago. Summary It all comes down to one very simple word: reusability. We can create an object once, and then use it anywhere. This leads to another phrase: rapid application development. But that's for another article. Reader Feedback: Page 1 of 1
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||