![]() |
|||
|
Editable LDMs
Mac/PC Text RTF Multiuser Trigonometry 2D Vectors |
Editable Text in Linked Director Movies
Source files: LDM.zip (Windows) | LDM.sit (Macintosh). You can create a There are, unfortunately, limitiations to interactivity. One of the major drawbacks is that you cannot edit text in the linked movie. This article shows you how you can work around this limitation. The technique is quite simple, in theory. The linked movie and the host movie share a You won't need to have any prior experience of Linked Director Movies. As I discuss the particular issues of editable text in an LDM, I'll also be introducing the general concepts, and touch on scope, encapsulation, and other Object Oriented topics, as well as giving tips on prototyping a new feature and on version control. Proving the concept (top) Let's start by proving that the shared member technique is workable.
Enabling scripts and cropping (top) One of the main reasons for using a linked movie is that visible area of the sprite can be smaller than the area of the linked movie's stage. The linked movie sprite gives you a viewport into a larger area. You can use scrollbars to move the linked movie's sprites around. This clips the sprites in the linked movie at the edges of the sprite on the host movie's stage. However, by default Shortly, we're going to be using code inside the Linked Director Movie. In order to get this code to execute when the movie is running inside a host movie, you'll need to enable the scripts. Both the
Save your new movie as Host_01.dir, then reopen the LDM_01.dir movie. We're going to add more text sprites and a behavior. Working with multiple To create a simple spreadsheet, we are going to need more than one In the Internal cast of the LDM_01.dir movie, create two new Select an empty cast slot in the External cast, then select both text sprites on the Stage, right-click on them (Windows) or Control-click (Macintosh) and choose Script... in the contextual menu that opens. This will add a behavior to both sprites: the behavior
Save your movie as LDM_02.dir. The shared external cast will have changed too, but it will retain the same name. Now reopen the Host_01.dir movie. Because you are working with linked files, you will need to change the link in the host movie. You can do this by selecting the Member tab for the
Note that the name of the member will not update to reflect the change in the fileName. Using static variables (top) When you are working with Linked Director Movies, it helps to avoid using global variables. If you have two sprites showing the same In the LDM_01 cast, create a new A better solution would be to use a script instance on the actorList. There is a unique actorList for each movie, whether it be playing on the Stage, in a sprite or in a window. Setting the focus of the editable sprite in the LDM (top) Open the behavior that you attached to the two text sprites in the LDM_02.dir movie, and enter the following on mouseDown(me)
script("Cell").SetFocus(sprite(me.spriteNum))
end mouseDown
Regardless of which text sprite you click on, the Here's are the properties and handler for the "Cell" script: property pOpenSprite property pOpenMember on SetFocus(me, aSprite) The Run the movie and test what happens if you click on each sprite in turn. Since we are making no attempt to move the editable sprite on the host movie Stage, the result is like having a separate input field in a spreadsheet application. Forcing an update (top) Test the Shockwave version below. You may notice that the height of the sprite being edited changes, if the
Understanding scope (top) The lag (or lack) of the automatic update can be hidden by placing the text sprite in the host movie at the same screen position as the appropriate sprite in the linked movie. This means that the linked movie has to be able to communicate with the host. The approach I use here is to ensure that code in the Linked Director Movie deals with what happens inside the Linked Director Movie,while code in the Host movie deals with what happens on the Stage. Communication consists simply of one movie telling the other what it should do, then leaving it to do it. In other words, the code executed in each movie is restricted to the scope of that movie. The fact that all the code for the feature can be stored in the same shared external cast is a bonus. Version control (top) As you saw earlier, saving a new version of a file under a different name can create version control problems. In the Host movie, you explicitly had to change the file path to the new version of the linked movie. Let's use a different technique, which maintains the links but uses more disk space. Create a new folder and copy all the files you have created into it. You can name the folder "Editable LDM". You can rename the files within it as LDM.dir, Shared.cst and Host.dir. You'll need to reset each of the links: to the shared cast and the linked
Communicating with the Host movie (top) In the Host movie, select an empty cast slot in the Shared cast, right-click or control-click on the LDM sprite on the Stage, choose Script... in the contextual menu, and paste the following property spriteNum property pSprite property pEditable Call this new behavior "LDM sprite behavior". Create a new movie script member in the Shared cast. This movie script will also be available to the linked movie: on SetLDMPort(anInstance)
script("Cell").SetLDMPort(anInstance)
end SetLDMPort
When the LDM sprite behavior is instanciated, it calls the SetLDMPort() handler in the movie script inside the LDM.dir movie, which in turn calls a handler in the "Cell" script. To get this to work, you'll need to edit the "Cell" script, and add a property declaration...
... add a new handler ...
on SetLDMPort(me, anInstance) pStageInstance = anInstance end SetLDMPort... and add a few lines to the end of the SetFocus() handler:
-- Ask the LDM sprite behavior on Stage to move the editable sprite
tLoc = pOpenSprite.loc
tell the stage
pStageInstance.SetEditableLoc(tLoc)
end tell
end SetFocus
So what effect do these changes have? When the LDM sprite behavior is instanciated, it gives the Cell script in the linked movie a mobile phone number. This is its "me" property, which tells the Cell script where to find it in the computer's RAM space. When the user clicks on a cell sprite, the Cell script uses that information to call the LDM sprite behavior and ask it to move the editable sprite on the stage. The LDM sprite behavior needs to convert the local co-ordinates that it is given to Stage co-ordinates, by adding the top-left point of the LDM sprite to the Disposing of outdated property values (top) When you first run your movie, you will have recompiled the Cell script, and everything should work fine. When you next run it, you may find that you have to click on a particular sprite in the linked movie in order to get the editable sprite on the Stage to move as it should. The reason for this is that the properties in the Cell script are maintained even after the movie is stopped. To test this, watch the following expressions in the Watcher window. (Note that these values are only accessible because the Cell script is not in the LDM.dir movie's internal cast: we are exploiting the leakiness that I mentioned earlier).
Stop the movie. The values remain. Restart the movie. The on stopMovie()And add this handler to the Cell script: on CleanUp(me) Try running several cycles of staring your movie, clicking on one or other of the sprites in the LDM sprite, and stopping the movie. Now that you are disposing of outdated property values correctly, the problem should have cleared up. Conclusion (top) This article has shown how to work around the fact that text inside Linked Director Movies is not directly editable. The demonstration movies in the download files are somewhat more complex than those described here. Indeed, you will find two versions of the movies: one uses the static script technique explained here, the other uses the actorList in a variety of ways to achieve the same ends. The ideas described here could be taken further. You might, for instance, want to have several LDM sprites sharing the same editable text sprite in the host movie. This implies that each LDM sprite is aware of its own state of focus, so that it can swap out the shared
|
||