Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

londonweb

macrumors 6502
Original poster
Sep 14, 2005
260
0
london
I've got a little problem in Flash that I just can't work out and it's driving me nuts because I've read 3 different manuals now and can't find any info about it.

My conundrum is this: I have a little script that scrolls a movieclip left and right when the user clicks either the left or right button. It works fine if the buttons and the movieclip are located on the same layer on the stage, however if I put the movieclip on a different layer to the buttons, it stops working.

It's a little thing that I've used for several websites now, and I've previously found ways around it so that the buttons and the movieclip are always on the same layer, but I'm working on something now where I really need them to be on different layers. No book I've scoured has so far indicated what I might be doing wrong, or if indeed this is simply not possible (I'm sure it is though). Perhaps I'm missing the wood for the trees...

Any ideas? If it helps I can post the code.

have a look at the following site and you can see the thing working: http://www.chrisbracewell.com
 

decksnap

macrumors 68040
Apr 11, 2003
3,075
84
Some code or some more explanation as to how you built it would help. I've never heard of a situation where something had to be in the same layer to be referenced correctly. What version of flash?

Maybe even a screengrab of the appropriate bit of the timeline...
 

londonweb

macrumors 6502
Original poster
Sep 14, 2005
260
0
london
decksnap said:
Some code or some more explanation as to how you built it would help. I've never heard of a situation where something had to be in the same layer to be referenced correctly. What version of flash?

It's Flash MX 2004 running on WinXP because my ibook died a couple of days ago, although the problem was exactly the same running on OSX.

Below are some grabs of the code and the timeline.

flashprob006.jpg


I've stripped away a lot of the stage to simplify it- basically there's a bit of motion tweening before the animation stops and then the user is supposed to be able to begin moving the images with the left and right buttons, but it doesn't work. If I remove the tweened part completely, it works...

flashprob007.jpg


Above is the first bit of code- the left button is a button behaviour nested in a movie clip. This is the script added to the button. When the user hovers, it moves left, and when they press, it moves left a bit quicker.

flashprob010.jpg


Above is the code on the left button Movie clip. When the button is hovered on or pressed, the images should move. 'fashion' is the instance name of the clip to be moved.

It seems to be all to do with the motion tweening, but I don't understand why. Any suggestions would be very welcome!
 

decksnap

macrumors 68040
Apr 11, 2003
3,075
84
OK- it's a bit early, but if what you're saying is that it gets messed up by adding the tweening, I have to guess it's somethng to do with your 'enter frame' clip event. Check what happens inside your movie clip when the 'enter frame' is invoked, because I think what's happening is that the 'enter frame' initiates at the beginning of the tween, not just at the end because it's all strung together.
 
L

littlejim

Guest
I can't look too hard at this and this is a long shot - but it's probably a bad idea to have a variable called 'press' as when you assign to it, you might be overwriting the event handler?

The other thing to try is use a global varaible e.g.

on( press ){
_global.pressed = true;
}

Globals aren't really good idea, but it may help in this case?
 

decksnap

macrumors 68040
Apr 11, 2003
3,075
84
I was thinking the same thing... although I don't think in this case it is the source of the problem. I'd say just for your own sanity, rename that variable to a word that doesn't have other actionscript meaning.
 

londonweb

macrumors 6502
Original poster
Sep 14, 2005
260
0
london
littlejim said:
I can't look too hard at this and this is a long shot - but it's probably a bad idea to have a variable called 'press' as when you assign to it, you might be overwriting the event handler?

That's a good point, although I never questioned it because it came out of a book and it works fine on my other sites. The enterframe event looks as though it could be the problem- I did wonder that, when looking at it earlier and wondered whether it could be some kind of conditional looping problem...
 

decksnap

macrumors 68040
Apr 11, 2003
3,075
84
So- try moving the instance of the 'left' that has the enter frame code on it to its own layer, and place it at the same spot it was in the timeline. Basically, the 'left' that is animating will be its own layer, then stop, and the 'left' that you interact with will be on its own layer, and the enter frame code won't get involved with the tweened frames.
 

londonweb

macrumors 6502
Original poster
Sep 14, 2005
260
0
london
decksnap said:
So- try moving the instance of the 'left' that has the enter frame code on it to its own layer, and place it at the same spot it was in the timeline. Basically, the 'left' that is animating will be its own layer, then stop, and the 'left' that you interact with will be on its own layer, and the enter frame code won't get involved with the tweened frames.

Hmmm. Tried it and didn't help....:confused:
 
L

littlejim

Guest
Have you put a trace on the onClipEvent( enterFrame ) function?
Is it being called at all? If so, if the value of 'press' 'undefined'?
 

londonweb

macrumors 6502
Original poster
Sep 14, 2005
260
0
london
decksnap said:
So- try moving the instance of the 'left' that has the enter frame code on it to its own layer, and place it at the same spot it was in the timeline. Basically, the 'left' that is animating will be its own layer, then stop, and the 'left' that you interact with will be on its own layer, and the enter frame code won't get involved with the tweened frames.

Ok, so it works if I move both the frame with the 'left' button and the frame with images onto their own layers. Problem solved, but there must be a more elegant way of doing this, no?
 

decksnap

macrumors 68040
Apr 11, 2003
3,075
84
Hard to say. Every flash file is very unique, but I usually would have all that stuff tied up in a movie clip so it didn't junkify my main stage. You can also use layer folders to keep your timeline clean.
 

londonweb

macrumors 6502
Original poster
Sep 14, 2005
260
0
london
decksnap said:
Hard to say. Every flash file is very unique, but I usually would have all that stuff tied up in a movie clip so it didn't junkify my main stage. You can also use layer folders to keep your timeline clean.

Thanks for all your help. I do consolidate things into movie clips sometimes, but then I get muddled because you can't see exactly what's happening when you scrub the main timeline. Any ways around this?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.