A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: onMouseWheel problem

Hybrid View

  1. #1
    Senior Member
    Join Date
    Apr 2006
    Posts
    431

    onMouseWheel problem

    Hi all,
    I have a scrolling dynamic text, and I made it support mouse wheel also.
    The scrolling text is part of a movie that loads externally (on _level2).
    I am making a site with the main menu on a level, and the other pages load on _level2 (so all pages are loaded externally, including the page with the scroller). I am saying this because my problem occurs when I visit another page (load another page on _level2), and then I come back to the page that contains the scroller (load the scroller movie on _level2) the mouse wheel works wird, meaning it scrolls more than it did last time.
    So the first time you visit the scrolling text page, the mouse wheel scrolls about 20 pixels with every scroll, if I press a button to visit another page and then come back, the mouse wheel will scroll about 60 pixels with every scroll, and so on. The distance keeps increasing, only if I go to another page and then come back. Weird ain't it?

    Here is the code (the onMouseWheel code is at the end)

    PHP Code:
    import mx.transitions.*;
    import mx.transitions.easing.*;

    var 
    First=_level3.loadXMLS[_level3.firstMovie]


    var 
    _css = new TextField.StyleSheet(); 

    function 
    loadXML(loaded) {
        if (
    loaded) {
            
    _root.info this.firstChild.childNodes[0].firstChild.nodeValue;
            
    _root.heights this.firstChild.childNodes[1].firstChild.nodeValue;


            
    _css.load("colors.css"); 
            
    _css.onLoad = function(){
            
    main.scroller.styleSheet _css
            pageTitles
    .styleSheet _css
                    _level3
    .preloader_mc.stop ()
            
    _level3.preloader_mc._visible false
            TransitionManager
    .start(_root.content_mc, {type:Wipedirection:Transition.INduration:1easing:Strong.easeOutstartPoint:6}); 
    }; 


            
    main.scroller.htmlText _root.info
            main
    .scroller.html true
            main
    .scroller.styleSheet _css
            main
    .scroller.autoSize "left";
            
    main.scroller.text _root.info;




            if(
    main.scroller._height mask_mc._height){
                
    up_btn._visible false;
                
    dragger._visible false;
                
    bar._visible false;
                
    down_btn._visible false;
            }


            
    bottom /*(main._y+mask_mc._height-main._height)*/ _root.heights
            
        
    } else {
            
    content "Error Loading File";
        }
    }
    myXML = new XML();
    myXML.ignoreWhite true;
    myXML.onLoad loadXML;


    if (
    First != undefined) {
        
    myXML.load(First)
    } else{
        
    Txt.text="No Xml file specified yet.."
    }

    //LOADING THE XML FROM THE main_menu.xml
    var File=_level3.loadXMLS[_level3.currentMovie]

    ///////////////////////////////////////////////////////////
    if (File != undefined) {
        
    myXML.load(File)
    } else{
        
    Txt.text="yoyo"
    }
    ///////////////////////////////////////////////////////////
    stop();

    space 0;
    friction 0.9;
    speed 4
    dragger._y;
    top main._y;
    bottom = (main._y+mask_mc._height-main._height-space) - _root.heights
    dragger
    .onPress = function() {
        
    drag true;
        
    this.startDrag(falsethis._xthis._parent.ythis._xthis._parent.y+this._parent.bar._height-this._height);
        
    dragger.scrollEase();
    };
    dragger.onMouseUp = function() {
        
    this.stopDrag();
        
    drag false;
    };
    bar.onPress = function() {
        
    drag true;
        if (
    this._parent._ymouse>this._y+this._height-this._parent.dragger._height) {
            
    this._parent.dragger._y this._parent._ymouse;
            
    this._parent.dragger._y this._y+this._height-this._parent.dragger._height;
        } else {
            
    this._parent.dragger._y this._parent._ymouse;
        }
        
    dragger.scrollEase();
    };
    bar.onMouseUp = function() {
        
    drag false;
    };
    moveDragger = function (d) {
        if ((
    dragger._y>=y+bar._height-dragger._height && == 1) || (dragger._y<=&& == -1)) {
            
    clearInterval(myInterval);
        } else {
            
    dragger._y += d;
            
    dragger.scrollEase();
            
    updateAfterEvent();
        }
    };
    up_btn.onPress = function() {
            
    myInterval setInterval(moveDragger20, -1);
    };
    down_btn.onPress = function() {
            
    myInterval setInterval(moveDragger201);
    };
    up_btn.onMouseUp down_btn.onMouseUp=function () {
            
    clearInterval(myInterval);
    };
    up_btn.onRollOver = function() {
            
    this.gotoAndPlay("over");
    };
    up_btn.onRollOut = function() {
            
    this.gotoAndPlay("out");
    };
    down_btn.onRollOver up_btn.onRollOver;
    down_btn.onRollOut up_btn.onRollOut;
    up_btn.onPress = function() {
            
    myInterval setInterval(moveDragger20, -1);
    };
    down_btn.onPress = function() {
            
    myInterval setInterval(moveDragger201);
    };
    up_btn.onReleaseOutside = function() {
            
    this.gotoAndPlay("out");
    }
    down_btn.onReleaseOutside = function() {
            
    this.gotoAndPlay("out");
    }
    MovieClip.prototype.scrollEase = function() {
        
    this.onEnterFrame = function() {
            if (
    Math.abs(dy) == && drag == false) {
                
    delete this.onEnterFrame;
            }
            
    = (this._y-y)/(bar._height-this._height);
            
    dy Math.round((((top-(top-bottom)*r)-main._y)/speed)*friction);
            
    main._y += dy;

        };
    };



    dragger.originY dragger._y;
    dragger.originX dragger._x;
    scrollSpeed 5
    //cosa=main.scroller._height/bar._height
    var mouseListener:Object = new Object();
    mouseListener.onMouseWheel = function(delta) {
        if(
    main.scroller._height mask_mc._height){
            
    trace("hihi")
        }else{
        
    dragger.scrollEase()
        }
        if (
    dragger._y>=dragger.originY) {
            
    dragger._y -= delta*scrollSpeed
            
    if (dragger._y<dragger.originY) {
                
    dragger._y dragger.originY;
            } else if (
    dragger._y>dragger.originY+bar._height-dragger._height) {
                
    dragger._y dragger.originY+bar._height-dragger._height;
            }
        }
    };
    Mouse.addListener(mouseListener); 
    Does anybody have any ideas on how to fix this?
    Thank you so much

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    moved from the XML forum to the Flash Actionscript forum
    (your problem does not relate to XML)

    your question might get more answers here

  3. #3
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Try clearing the interval before going to another page and/or removing the mouse listener.

  4. #4
    Senior Member
    Join Date
    Apr 2006
    Posts
    431
    Hi, and thank you for replying. I doesn't have to do anything with the interval, it just works weird. I can't really udnerstand why. I even tested it separately, without any extracode, just this:

    PHP Code:
    var mouseListener:Object = new Object();
    mouseListener.onMouseWheel = function(delta) {
        
    test_mc._y -= delta
    };
    Mouse.addListener(mouseListener); 
    And if this movie that contains the test_mc movieclip is loaded into _level2 for example, and you press a button and another movie is loaded into _level2, and then press another button to reload the main movie that contains text_mc, delta will get higher and higher with each time you do this operation. Every time you unload MC_TEST.swf - load another movie.swf - then reload MC_TEST.swf (where MC_TEST.swf is the movie that contains test_mc), when you scroll once, you scroll larger and larger distances. It's really weird.
    Anybody experienced something like this before?

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