dynamic button issue

  • roarmeow
  • Professor
  • Professor
  • User avatar
  • Posts: 861
  • Loc: BKNY

Post 3+ Months Ago

alright.
so i've got these movieclips.
each movieclip is made up of two frames:
frame 1: an image and a stop(); script
frame 2: a word and a stop(); script
the image for each one is a dynamically loaded .jpg
Code: [ Select ]
_root.main_section.main_section_mc.loadMovie("section.jpg");


i've made it so that, when you roll over the mc, the word is there and when you roll out, the image is there with the following script:
Code: [ Select ]
onClipEvent (enterFrame) {
if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
this.nextFrame();
} else {
this.prevFrame();
}
}
  1. onClipEvent (enterFrame) {
  2. if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
  3. this.nextFrame();
  4. } else {
  5. this.prevFrame();
  6. }
  7. }


this works just fine.

however, when i try to add an action to it, as below:
[code] onClipEvent (enterFrame) {
this.onRelease=function(){_root.gotoAndPlay("mainout");}
if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
this.nextFrame();
} else {
this.prevFrame();
}
}/code]

it just straight screws up. the mc disappears off the page on the frame when this script is applied to it.
does anyone know why that one line should be all wonky? or if there's another way to do this, i'd love to hear about that.

peace and thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • roarmeow
  • Professor
  • Professor
  • User avatar
  • Posts: 861
  • Loc: BKNY

Post 3+ Months Ago

what i found to be the problem is that if the actionscript on the mc in question is different in one frame than it was in another, on the frame where it changes, it just disappears...

does anyone know why this is?
it kinda sucks.
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Ok, well I am very confused about what the problem is, do you have an example .fla?

What I can tell you right now is that your syntax is quite off.

You should never define an event within an event... especially an enterFrame because then it just keeps overwriting itself.

And second, Why is there a hitTest check in an onRelease? If you released the button, then your mouse must be over it right? And if not, nothing will happen, for something to happen if you release the mouse off of the clip you need to define a releaseOutside event.

Also you have to be careful with manipulating frames. While you can control multiple timelines, you have to make sure the timelines you are controlling at the same time don't conflict with eachother. Like if you change the location on the _root timeline and the other timeline you are trying to manipulate doesn't exist on the frame where you make the _root timeline go.
  • roarmeow
  • Professor
  • Professor
  • User avatar
  • Posts: 861
  • Loc: BKNY

Post 3+ Months Ago

lostinbeta wrote:
And second, Why is there a hitTest check in an onRelease? If you released the button, then your mouse must be over it right? And if not, nothing will happen, for something to happen if you release the mouse off of the clip you need to define a releaseOutside event.


first off, glad you noticed about my syntax being off. i'd love to know another way to do this for sure, but as i've pretty much taught myself, well, it's kind of a mess no doubt.

anyways, for the second question you had, the hittest is just for a rollover effect on the button. the onRelease is for the effect of the button. get it?

when someone rolls over the button, it changes what it looks like (movement within the button movieclip's timeline) and when they click on it, it actually affects the _root timeline.

now, as far as it being dangerous to mess with timelines, that's not really the problem, because the problem occurs even if i don't mouseover or click on the button movieclip. the actual timeline even it triggers is just peachy.

check out the fla here:
http://www.roarmeow.com/wip/flash.fla

anyways, thanks for the reply and i appreciate you looking into this. if there's any references you have for remediating my delinquent syntax, please do...

peace,
puck
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Ok, well if I understand what you are trying to do correctly, the fix is VERY easy.
Code: [ Select ]
onClipEvent (enterFrame) {
    if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
        this.nextFrame();
    } else {
        this.prevFrame();
    }
}
on (release) {
    _root.gotoAndPlay("mainout");
}
  1. onClipEvent (enterFrame) {
  2.     if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
  3.         this.nextFrame();
  4.     } else {
  5.         this.prevFrame();
  6.     }
  7. }
  8. on (release) {
  9.     _root.gotoAndPlay("mainout");
  10. }


Just use a static handler on(release) instead of the dynamic handler onRelease and move outside of the static onClipEvent handler enterFrame. The wondeful thing about Flash MX and up is that movieclip symbol allow the use of on handlers. Flash 5 and below only allowed on handlers for button symbols.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 12 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.