A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [F8] Help with a scrolling background w/ mouseover

  1. #1
    Member
    Join Date
    Mar 2002
    Location
    Hollywood, CA
    Posts
    50

    [F8] Help with a scrolling background w/ mouseover

    Hey guys --

    I'm working on this website that has a background that scrolls with the mouse. I am having two difficulties:

    1.) Making sure the images don't scroll off the viewing area.
    2.) Making sure the mouse scroll only happens in the specific window pane.

    I have two flash files. Index.swf contains the background (the oily/dirty wall), which is importing Index2.swf using a MovieClipLoader.

    In Index2.swf, I've taken my three layers (Fore, Mid, and Back), and combined them into one movieclip. Then, I am using this AS to control the scrolling:

    Code:
    onClipEvent (mouseMove) {
     xmousepos1 = _xmouse;
     ymousepos1 = _ymouse;
     if (xmousepos1>xmousepos2 && ymousepos1>-10 && ymousepos1<-10) {
     _root.scrollclip.nextFrame();
     }
     if (xmousepos1-10 && ymousepos1<-10) {
     _root.scrollclip.prevFrame();
     }
     if (ymousepos1<-10 || ymousepos1>-10) {
     play ();
     }
     xmousepos2 = _xmouse;
     ymousepos2 = _ymouse;
    }
    I just don't know where to define the limits. My images are 1024 wide, width of the player is 1000, but the area I want the scrolling to take place in is 770.


    You can see my progress here:
    http://www.liberateart.com/xroze/


    I'm really pleased with the results so far, just trying to tweak this to make it work. I've gone through a couple tutorials, but this case is a little difficult, because I'm loading a movie into a movie. Any help would be GREATLY appreciated!

    DOWNLOAD FLA FILES (2.5MB)
    http://www.liberateart.com/FK_Help.zip

    Eric T.
    Last edited by EJTrowbridge; 04-27-2007 at 06:31 AM.

  2. #2
    Senior Member layerburn's Avatar
    Join Date
    Jul 2006
    Location
    USA
    Posts
    542
    Have you looked at the scrolling thumbnail panel tutorial at gotoandlearn.com?? I think it's exactly what you're looking for. It shows you how to have a "hit" area and define the limits so it doesn't keep scrolling when it's reached the end. Here is the link to the download page, grab "Scrolling Thumbnail Panel". It would be easier than me trying to explain it since I'm really bad at explaining. He explains everything step by step for you. I hope this helps.

    http://www.gotoandlearn.com/download.php
    This is your brain. This is your brain on script.

  3. #3
    Member
    Join Date
    Mar 2002
    Location
    Hollywood, CA
    Posts
    50

    One step closer...

    Thanks for the link man! Gotoandlearn.com is a great resource. I really liked the much cleaner code that he used versus to what I was using.

    However, I do like in my original version how it "eases" in and out. Gotoandlearn's is a little choppy. Also, he really just explains how to take one movie clip with one layer to scroll it. I have one movie clip with three different layers that need to scroll at different speeds (to achieve the effect).

    I'll mess around with the code when I get back from work today, but any further comments and how I could accomplish this would certainly be useful.


    ET
    Eric

  4. #4
    Senior Member layerburn's Avatar
    Join Date
    Jul 2006
    Location
    USA
    Posts
    542
    Here's exactly what my code looks like, for my project I got help working in a easeOut effect to take care of the choppiness. See if it helps yours out at all. I really liked how you had the layers in yours. I'm not sure how you would work that in, but I'd been interested in seeing your results, it will look really nice when you get done.

    Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    //
    function tweenB(mc, xdist) {
    	var begin = Math.round(mc._x);
    	if (xdist > 0) {
    		var trvl = 132 - Math.abs((begin + 40) % 132);
    		var end = begin + (trvl * -1);
    	} else {
    		var trvl = 132 - Math.abs((begin - 32) % 132);
    		var end = begin - (trvl * 1) + 132;
    	}
    	if (begin >= 27) {
    		end = 27;
    	}else if (end <= -4265) {
    		end = -4265;
    	}
    	var time = 1;
    	aTween = new mx.transitions.Tween(mc, "_x", mx.transitions.easing.Strong.easeOut, begin, end, time, true);
    	aTween.onMotionFinished = function() {
    		//trace("done");
    		
    	};
    }
    //
    panel.onRollOver = panelOver;
    function panelOver() {
    	this.onEnterFrame = scrollPanel;
    	delete this.onRollOver;
    }
    var b = stroke.getBounds(_root);
    function scrollPanel() {
    	if (panel._x >= 27) {
    		panel._x = 27;
    	}
    	if (panel._x <= -4265) {
    		panel._x = -4265;
    	}
    	var xdist = _xmouse - 225;
    	panel._x += -xdist / 17;
    	if (_xmouse < b.xMin || _ymouse < b.yMin || _xmouse > b.xMax || _ymouse > b.yMax) {
    		tweenB(this, xdist);
    		this.onRollOver = panelOver;
    		delete this.onEnterFrame;
    	}
    }
    This is your brain. This is your brain on script.

  5. #5
    Member
    Join Date
    Mar 2002
    Location
    Hollywood, CA
    Posts
    50

    Awesome..

    Thanks for all your help layerburn. I'm at work right now, but I'll mess around with it this evening to see if I can get it working. I'll post my findings!

    ET
    Eric

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center