| Changing
Properties Dynamically (with actionscript) You have to make a variation on this file. (press and hold the buttons) Requirements: 01. Your file must change the same properties I do in my file:
That's 3 properties to change (if you have time and all goes well, you can add other properties, like y, height, rotation, etc. 02. Your file must also constrain your changes with if statements, if necessary. Not all properties need one! Think about this: the _visible property has no need for an if statement in this assignment. Things are either visible or not! Nor does it require an ENTER_FRAME command - you want it instantly visible or invisible.... Refer to the bottom part of the lecture for more info on using "if statements". Under the words "if you don't mind" in bold. At the very end of this week's lecture, I provided an example of what to write in a button that would increase the x coordinate of a mc named car_mc as long as this car_mc didn't reach the end of the Stage. Remember that an x coordinate of 0 pixels is the left edge of your Stage and a y coordinate of 0 is the top of your Stage. Here's that button code as I wrote it at the bottom of the lecture and as it can be found in my file::
Notice in my example that the object I move around sometimes starts its motion when I press a button and stops when I release it. This is why I need both a "MOUSE_DOWN" and a "MOUSE_UP" part as you can see above. Notice also the very first line which is just a comment line that explains what the code below it is about. When you are starting to have a lot of code in a keyframe, it is good practice to add these textual separators to organize your code. 03. Your file must
also have a "reset" button. Where should I start? You should start by creating your symbols. What symbols do I use in my file? Only two, a "square" movie clip symbol and a button. The button is made with instances of my square mc and the grey "box" on Stage is also an instance of my square mc. Then place instances of both your target mc (the mc you will manipulate) and your buttons. Give your target mc an instance name (like "car_mc") and then copy&paste the above code (with the first comment line) in the Actions panel (yes, the Actions panel is like a text editor - especially in Expert Mode) and you can copy&paste code to and from it). Then name your button correctly (like "go_btn"), and test your file right away. If it works, we're in business! :) Remember that the code for the other buttons is quite similar (except for the visibility button which requires less code). Since the code is similar for the other buttons, here's how I would do my second button code: copy the working code below itself and just edit the code for each button instance so the if statement and the property names are adapted to each button's purpose. Remember some properties don't need if statements and/or onEnterFrame commands. You just use your logic Now the only thing left to do is the Reset button. The Reset button should bring each and every "box" property back to its original state, when the file first opens up. The box should recenter, the visibility back to true, etc. This means the function for your reset button will obviously contain a list of simple commands. Here's how mine looks:
(I omitted the button code itself here, but hey, I can't give the answers for all parts of this assignment! ;)) Other details: my file is one frame long and has only one layer. You may wish to read this page again if you experience difficulties or if you want to make sure you didn't forget anything! Have fun! Stéphane
and Damien . |