flash actionscript:
Hello. I have a movie clip that is instantiated a lot of times on one frame. This movie clip has 3 frames (much like a button with 3 states). There is a button on the frame that when it is clicked should change the state of a particular instance of that movie clip. So lets say that mc_instance1 is displaying its frame1. on (release) { mc_instance1.nextFrame(); } doesn't want to work. any inputs? thanks
Hello, I'm assuming you have a stop(); at every frame to keep it in its state. I'm not too sure about the method nextFrame, so I would use something more like this: on(release){ if(mc_instance1._currentFrame <= 2){ mc_instance1._currentFrame += 1; }else{ mc_instance1._currentFrame = 1; } } Hope that helps. Good luck!
Ugh, I'm writing this for the second time (although I'm probably shortening it up), so I hope it's worth it! I need to correct a couple things from my own code. Add _root or a _levelN reference to the the start of every movieclip name. Here is an example where you can use a function to save yourself from copying the code to several movie clips. Timeline: // the function needs the chosen mc and its current frame function mc_advance(mci, mci_cf){ // just reusing the previous code using variables // note: don't need _root because it will be included if(mci_cf <= 2){ mci_cf += 1; }else{ mci_cf = 1; } Button (it's easier if the mc is its own button. use 'this' instead of the entire instance name): on(release){ // the currentframe property is all lowercase // I forget if you need the quotes or not mc_advance("_root.mc_instance1", _root.mc_instance1._currentframe); } using the mc as the button, the above line becomes: mc_advance(this, this._currentframe); Hope I've helped. Sorry for the code typos and other mistakes!
Ps. About the first line of the last message:
Banana is quite right that the problem is a _root reference. But your original use of nextFrame() was correct and much more tidy than defining functions and so on. Taking your original example with an instance of mc_instance1, all you need to do is write this: on (release) { _root.mc_instance1.nextFrame(); } That's it! Alternatively you could make your actionscript tidier still by putting all the script in the main timeline. If we say your button instance is called bt_instance1, the example would go as follows: bt_instance1.onRelease = function () { mc_instance1.nextFrame(); }; But, the choice is yours. Hope this helps and apologies if I've misunderstood you or Have A B. ::Nephthys
In Reply to Nepthys101 It probably would suit you more to use the nextFrame() method. I don't seem to think in the 'conventional' manner, so I disagree with people often. nextFrame() may be exactly what you're looking for, but here is a question from me: will the frame cycle back to the start when it gets to the last one? Concerning the use of functions, I like to keep any code I write adaptable to any objects I create. I am still working on my programming skills, but I like to think I make progress every day. As a final query, I haven't seen any way to declare the same release function for many objects at once. I like to be efficient and spend as little time coding as possible. It would be nice if, for example, I knew of a way to give all buttons in a certain folder of my library the same function for on(release) that references their name.
This code doesn't seem to work either , so I assume the problem is in a different place. So I take the following steps: I create a movie clip that contains a circle. Inside the movie clip I create 3 frames for the circle with different colors. I instantiate the movie clip once and call the instance: mc_instance1. Except for the movie clip on the scene there is also a button. When I click the button I want the circle to change color. Yes I have a stop() function to keep it in state. Thanks
I guess the coding side still offers enough opportunity for personal expression! I didn't mean to criticise your approach - I myself still have plenty to learn :) ... Indeed, I do also agree with you in general about the use of functions. It's just I felt there was a problem with using only _currentFrame alone to instruct the movie clip because I'm sure it's a read-only property. Which would mean as far as Flash is concerned mc_instance1._currentFrame += 1; is meaningless and wouldn't do anything. On the other hand, nextFrame() is an action - an actual instruction to the playhead. But you're right that is doesn't account for coming to the end of the movie clip. My code would need to incorporate your conditional, so it should probably look something more like this: bt_instance1.onRelease = function () { if(mc_instance1._currentFrame==x){ mc_instance1.gotoAndStop(1); } else { mc_instance1.nextFrame(); } } Where x is the last frame number in the movieclip. This would all be contained in the timeline again. As for your final query, I'd like to know the answer to that too! I don't know offhand of an efficient way to do it.
Don't see what you're looking for? Try a search.
|