The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.34 / 5.00 31,296 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.07 / 5.00 10,082 ViewsHello all.
Anyhow, I was fiddling around to come up with some way to get flash to respond to use of the scroll wheel on the mouse. If there were a way to upload a .fla, I would have done that... Anyhow I'll explain where stuff goes in the experiment and paste the relevant code... Should be easy peasy to reproduce it.
Here's the bit that I put on the main timeline in the first frame:
var mwDelta:Number = 0;
var mwTar;
// Following stuff detects mouse wheel scrolling
mwListener = new Object();
mwListener.onMouseWheel = function(delta, scrollTarget) {
mwDelta = delta;
mwTar = scrollTarget;
return mwDelta;
return mwTar;
};
Mouse.addListener(mwListener);
And then I made 3 different movie clips. One that rotated, one that scaled, and one that flipped frames. I'll show rotation and frames, since scaling code was almost same to rotating (should be easy to figure out)...
On the rotating_mc:
// Following activates turner function inside clip
onClipEvent (enterFrame) {
this.turner ();
}
And inside the rotating_mc:
function turner() {
if (_root.mwTar == this) {
this._rotation -= _root.mwDelta;
}
}
Then on the flip through frames one:
onClipEvent (enterFrame) {
this.checkScroll();
trace("delta: "+_root.mwDelta+" target: "+_root.mwTar);
}
I did some tracing to see what's going on, since I'm newb to scripting and wanted to see what was going on (if anything). You could omit that.
And inside the flipping frames one:
stop();
function checkScroll() {
if (_root.mwTar == this) {
if (_root.mwDelta>0) {
nextFrame();
} else if (_root.mwDelta<0) {
prevFrame();
} else {
stop();
}
}
}
Believe it or not, that actually did something. 3 Items responding to the mouse wheel in flash, of course not forgetting to click somewhere on the flash to give it focus. (But I think there's a trick somewhere to auto-focus a flash when on the web.) I think the concept behind this would have some uses in actual games or interfaces.
But now I have some questions based on the experiment:
Is that the most efficient way to do something like that?
Good, bad, or ugly code? (I'm still newb, not to mention more artist than programmer anyhow.)
I noticed some lag-like behavior in response to scrolling. How often does the listener update? (Guessing its at framerate in this example, but my trace that updates on a "onFrameEnter" shows repetion 3-4 times.) It's a bit annoying, since the scroll behavior seems to overshoot because of this. (More noticable on the frame flipper.)
And when checking the trace values for scroll delta, I aways get something like +3 or -3. Is that normal? Or do my WinXP control panel mouse scroll settings actually effect that?
Did a lookup on the topic of streaming or syncing because it's a problem I ran into. Noticed there were seemingly 100s of threads on the subject. Some might have a glint of useful info, but others didn't say much of anything. If it's that common a problem, there should be a really good FAQ or tutorial made about the subject.
Things I've noticed so far going through threads or trying stuff...
Scenes break streaming functionality. (Figured this much out on my own...)
Preloading might help. But then again it might not. (Not much of a choice on long anims though.)
Multiple sound clips break streaming. (Can't figure out the workaround, and has me banging my head on the wall.)
Someone said something about using movieclips to time and synch the audio, does this work well?
Also does frame rate have anything to do with how well this works? (Is it less likely to be off with a lower frame rate?)
Different filetypes or encoding were suggested, saying to use this or that...
It'd probably help a lot of flash newbs. And info would be great so movies don't have dialog looking like badly dubbed kung-fu flicks. (Or at least when it's not intentional.)