News:

If you need instructions on how to get through the hotels, check out the enclosed instruction book.

Main Menu

AS dilema

Farted by Plug Clock, March 26, 2010, 07:26:19 PM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Plug Clock

I need help with actionscript
I'm trying to program a button in my latest project to direct a movie clip to proceed to another frame inside said movie clip, but that's not all. I also want it to go to a different movie clip depending on what frame the movie is on. I've researched this for a good while and the only thing I've learned is to not trust Actionscript.org to help you with your actionscript problems.

I tried using Dynamic text to direct the movie clip to which frame I want it to go to. I have some blank dynamic test from frame a to frame b with the instance name of "Picture", and the actions of the usual stop; and Picture=1;
Then I have a button inside a movie clip with this code assigned to it.
on (press){
_root.pos = SharedObject.getLocal("cookie");
_root.picture = _root.pos.data.picture
}
on(release){
if(_root.picture==1){
gotoAndStop(101);
}
if(_root.picture==2){
gotoAndStop(102);
}
if(_root.picture==3){
gotoAndStop(103);
}
if(_root.picture==4){
gotoAndStop(104);
Obviously this doesn't work.
Any Idea what I'm doing wrong?

RomanClock

It wont load the shared information by the time you release the button so picture will be undefined. You should load the cookie in the first or second frame of the movie and not on this button press. If you need to keep it on the button, what you'll have to do is call a method that will check when the data is loaded and then go to the specified frame.

The description of what you are trying to do was confusing, can you try and explain it differently?

PS: Post in programming forum.
lemayo lol :soups:

Plug Clock

Would it help if I posted the source file?

Loki Clock

If you're relying on the on(press) event to make sure that its code is executed before the on(release) code, don't bother. Just put them all in one trigger.

Plug Clock

#4
Thanks for the help. I got it to work partially. I can click on a button at the top right corner to take me to the frames in the movie clip, and a button to take me back to frame 1 of the movie clip, but when I try to import the movie clip, code, and dynamic text into another flash, it doesn't work, even though the frames, instances, names, and actions are all the same.
I double checked everything. I made sure if the dymanic text instance names were case sensitive; they're not. I made sure all the code was the same and where it should be; it is. I made sure the instance names matched and directed what I wanted it to do; everything is the same as in the sample below. There are two dynamic text entries in the root timeline however, but one is on a separate layer and it has a completely different instance name. So nothing should be interfering with this.
http://files.myfrogbag.com/f01go0/ccsample.swf

Here's the new code applied to the first frame of the movie clip on a blank layer.
stop();
save.onRelease = function() {
_root.pos = SharedObject.getLocal();
_root.picture = _root.pos.data.picture
if(_root.pocket==1){
    gotoAndStop(2);
}
if(_root.pocket==2){
    gotoAndStop(3);
}
if(_root.pocket==3){
    gotoAndStop(4);
}
if(_root.pocket==4){
    gotoAndStop(5);
}
if(_root.pocket==5){
    gotoAndStop(6);
}
}

I'd go into further detail about all this, but I'd have to provide lines of code, and dozens of screenshots to get everything in, but hey, whatever it takes.

Loki Clock

You can send movie clip control commands to other movie clips as, e.g., instancename.gotoAndPlay();. There's a switch/case mechanism in Flash.  More importantly, there's a nextFrame() command.

What version of actionScript is this? AS2?

Plug Clock

Quote from: Scalppussyhello;1742639You can send movie clip control commands to other movie clips as, e.g., instancename.gotoAndPlay();. There's a switch/case mechanism in Flash.  More importantly, there's a nextFrame() command.

What version of actionScript is this? AS2?
yessir

Loki Clock

Other stuff: You should use _parent instead of _root, so that the code will work even with the system embedded in a movie clip of its own. If this particular movie clip only has one frame that will ever be used, get rid of or move any other frames it may have, and remove the "stop" line, which will thenceforth do nothing. Dilemma has a dimu.

Plug Clock

#8
Well, I took your advice, but the problem is the button won't do what I want it to when I click on it, even though everything works fine in a separate flash file.

Loki Clock

Quote from: Plug Clock;1742699Well, I took your advice, but the problem is

Yeah, sorry. I'm out of practice with AS2, so I can't really address your problem, but I figured I could at least help with that.

Plug Clock

#10
That's fine. I'll figure something out. Thanks for your help!

Edit: I got it to work! I just moved everything to a new file.