1
votes

I have 2 symbols in a frame: deer and man. I want to stop the flash movie on frame 45 and if user clicks on deer play frames 50-100 but if user clicks on man I want to play frame 200 - 250. The code I have in frame 45 is:

stop();
var _buttons:Array = [deer, man];

for(var i = 0; i < _buttons.length; i++){
    _buttons[i].onRelease = function() {
        gotoAndPlay(100);
    }

    _buttons[i].onRelease = function() {
        gotoAndPlay(200);
    }
}

when movie stops on frame 45 and I click on an object nothing happens but there are no errors.

3
Try to remove private word before function. - Engineer
then i get error interface 'MouseEvent' could not be loaded. - just eric
There needs to be an import flash.events.MouseEvent before the rest of your code. - Pranav Hosangadi
@PranavHosangadi I get error interface 'flash.events.MouseEvent' could not be loaded. ? - just eric
This seems to be some idiosyncrasy of AS2, something I stopped putting my head to long ago. If you're making something new, why not use AS3? - Pranav Hosangadi

3 Answers

2
votes

If you are using ActionScript 2, the issue you run into is a classic object scope related problem. It is not ActionScript 2 fault, but JavaScript specification. Consider the following snippet

trace(this);  // it displays the movieclip that hosts the button
myButton.onRelease = function() {
    trace(this);  //oops, it is the button, not the host.
}

One quick hack to get around this without resorting to _root would be

stop();
var _buttons:Array = [deer, man];

trace("deer button: " + deer);
deer.context = this;
deer.onRelease = function() {
    trace("deer button is clicked.");
    deer.context.gotoAndPlay(100);
}

trace("man button: " + deer);
man.onRelease = function() {
    trace("man button is clicked.");
    man.context.gotoAndPlay(200);
}

A much more elegant implementation would be using delegate, so you don't have to hard-code _root or "context" properties.

1
votes

try:

deer.onRelease = function() {
   this.gotoAndPlay(50);
   // make sure that is an stop(); Action on frame 100
}

man.onRelease = function() {
   this.gotoAndPlay(200);
   // make sure that is an stop(); Action on frame 250
}

How you named the sensitiv Moviclip or Button - "deer" & "man" ? It's better you works with named Frames not with frame number. Goto a keyframe a rename the keyframe. Then you can write for example: this.gotoAndPlay("man_start");

You tag it as AS2 - I hope I can help you. Best regards

EDIT: Make sure that you have the right path for the gotoAndPlay. You can write for example _root.gotoAndPlay("man_start") when the Button/clip on the root timline. If the button is in the man clip you can write for example:

deer.your_named_button.onRelease = function() {
    this._parent.gotoAndPlay("man_start");
}
1
votes

Now you can write in the action panel from the first keyframe("start", keyframe 0):

stop(); // you have write it in the first step

// klick on your deer button and name it "deer_btn", if isn't it
deer_btn.onRelease = function() {
    _root.gotoAndPlay("play_deer");
    trace("I pressed deer_btn"); // can you delete later
}

// klick on your man button and name it "man_btn", if isn't it
man_btn.onRelease = function() {
    _root.gotoAndPlay("play_man");
    trace("I pressed man_btn"); // can you delete later
}

This should be work, but it's untested. No Flash on the notebook. I hope it helps you. May not - ask me.