Skip navigation
Currently Being Moderated

Rollover scrolling menu - no buttons

Feb 29, 2012 6:35 AM

Tags: #as3 #rollover #no_button #scrolling_menu

So below is my code for a project I'm working on. I'm having some trouble though. I got the code for the scrolling menus online from another forum, but I can't figure out where that was. In any case, the current version of the code allows for the scrolling to happen when I open the page displays (enter Frame). But I can't figure out how to get the scrolling to happen only when I hover over the menu. Can anyone help? I only want each one to scroll when I hover over the menu, not when I get on the page. I tried to replace the "enterFrame" part of the code, but it didn't work right. I need this done ASAP. Thanks in advanced!

 

import fl.transitions.Tween;

import fl.transitions.easing.*;

 

 

var mymovie = this;

var mymovieW = this.width;

 

var horizontalMode = 0;//1--horizontalMode; 0--verticalMode

var spaceImg = 7;//space beteen images

var fade = 0.5;

var containerPosition_x = 2;//put the container with images to the buttom of the stage

var containerPosition_y = 1;//put the container with images to the right of the stage

var yoffset = 10;//offset to adjust the position of big image on y axis

var xoffset = 10;

 

var numItems;

var objects;

 

var container:MovieClip = new MovieClip();

this.addChild(container);

var scrolling:Boolean = true;

var useFixedImageSize = 1;

 

var thumbnails:Array = new Array();

 

 

//load xml file

 

var xmlData = "Photoimages.xml";//set xml data file

 

var xmlObj:XMLDocument;

 

init();//init call -> load config XML and create objects

 

function init()

{

    xmlObj = new XMLDocument();

    xmlObj.ignoreWhite = true;

 

    var loader:URLLoader = new URLLoader();

    var request:URLRequest = new URLRequest(xmlData);

    loader.load(request);

 

    loader.addEventListener("complete", onComplete);

    loader.addEventListener("ioError", onIOError);

}

 

function onIOError(event:Event):void

{

    trace("IOERROR (maybe XML file does not exit or have an incorrect name)");

}

 

function onComplete(event:Event):void

{

    var loader:URLLoader = event.target as URLLoader;

    if (loader != null)

    {

        xmlObj.parseXML(loader.data);

        xmlHandler();

    }

    else

    {

        trace("Loader is not a URLLoader!");

    }

}

 

function xmlHandler()

{

    addObjects();

    startEngine();

}

 

function startEngine()

{

    container.addEventListener("enterFrame",startMovie);

}

 

function addObjects()

{//add objects in the scene

 

    objects = xmlObj.firstChild.childNodes;

    numItems = objects.length;

 

    for (var i=0; i<numItems; i++)

    {

        var attr = objects[i].attributes;

        //Set the images

        thumbnails[i] = attr.thumb;

        init_thb(i);

    }

}

 

function init_thb(i)

{

    if (useFixedImageSize == 1)

    {

        var source1 = "AudioimgMc";//image mc linkage id from the library

    }

    else

    {

        source1 = "imgMc_01";

    }

    var sourceType1 = "library";

    var regName1 = "p" + i;//the registration name used in Flash

 

    var classDef = getDefinitionByName(source1);

    var menuItemMc = new classDef  ;

    menuItemMc.name = regName1;

    container.addChild(menuItemMc);

    var myThumbMc = container.getChildByName(regName1);

 

    myThumbMc.buttonMode = true;

    myThumbMc.useHandCursor = true;

    myThumbMc.mouseChildren = false;

 

    myThumbMc["info"] = objects[i];

 

    myThumbMc.y = (myThumbMc.height+spaceImg)*(i);

    myThumbMc.x = (bkg.width-myThumbMc.width)/containerPosition_y;

    myThumbMc.alpha = fade;

    myThumbMc.addEventListener("mouseOver",mouseRollOver);

    myThumbMc.addEventListener("mouseOut",mouseRollOut);

    myThumbMc.addEventListener("mouseDown",mousePress);

}

 

function mouseRollOver(e:MouseEvent)

{

    e.target.alpha = 1;

 

}

 

function mouseRollOut(e:MouseEvent)

{

    e.target.alpha = fade;

 

}

 

function mousePress(e:MouseEvent)

{

    navigateToURL( new URLRequest( e.target["info"].attributes.url ), "_blank" );

 

}

 

function startMovie(e:Event)

{

    this.container.y += Math.cos((-stage.mouseY/stage.stageHeight)*Math.PI)*15;

        if (this.container.y > 0)

        {

            this.container.y = 0;

        }

        if (-this.container.y>(this.container.height-stage.stageHeight))

        {

            this.container.y = -(this.container.height-stage.stageHeight);

        }

}

 
Replies
  • Currently Being Moderated
    Feb 29, 2012 7:01 AM   in reply to prashant.savalia1

    Looks like it's starting to scroll on page launch and you say you only want that to happen if the user rolls over the item?

     

    What's starting the scrolling is this:

     

    function xmlHandler()

    {

        addObjects();

        startEngine();

    }

     

    It adds the objects, then starts the engine which adds the enterframe listener. You might want to adjust that to:

     

    function xmlHandler()

    {

        addObjects();

        container.addEventListener(MouseEvent.MOUSE_OVER,startEngine,false,0, true);

    }

     

    Then in the startEngine() function:

     

    function startEngine(e:MouseEvent)

    {

        container.removeEventListener(MouseEvent.MOUSE_OVER,startEngine); // cleanup

        container.addEventListener("enterFrame",startMovie);

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 25, 2012 3:58 PM   in reply to prashant.savalia1

    Welcome

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 19, 2012 11:33 AM   in reply to prashant.savalia1

    Sorry my time is short but beifly scanning, you cannot create a new "var source1" like you are trying. The linkage ID becomes a full "class".

     

    Thus your instantiation should look like:

    var source1:MovieClip = new PhotoimgMc();

     

    or

     

    var source1:MovieClip = new AnimationimgMc();

     

    or

     

    var source1:MovieClip = new AudioimgMc();

     

    If the "type" of the symbol differs (like to Sprite, etc) then change MovieClip to be whatever type it is.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 19, 2012 12:00 PM   in reply to prashant.savalia1

    Can you paste the relevant code on the frames that are erroring?

     

    And if you don't want MovieClips (which play by default) to play, then add an actionscript layer to them and add the stop() command in a frame script so they don't auto-play. You'll need to play() them once you're ready though.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2012 6:21 AM   in reply to prashant.savalia1

    There's a missing XML on that page that apparently has image names in them. All I'm getting is your IOError from your XML error handler.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2012 9:40 AM   in reply to prashant.savalia1

    At a quick glance it seems you're setting listeners over and over and over. Oddly in the 2 sliding image areas on left and right in services you remove an event listener so you know you can do that. But on the main frames you keep assigning the buttons (like Home, etc) over and over. This will result in adding a ton of listeners stacked up.

     

    I added the listeners once on the second frame and removed the assignment from then on. I also moved some of the redundant import statements to frame 1. As long as you import anything on frame1 in a timeline, the rest of the timeline can use it.

     

    The only errors I could see was due to you adding an onEnterFrame listener to those vertical sliding images but you never removed it. Once you go off the frame they kept firing off causing a spray of errors. I just adjusted it so on MOUSE_OUT it would remove the onEnterFrame and I don't get the errors anymore. I added a stopEngine() function that you can look at. I duplicated that for both of the sliders code.

     

    This is just the index saved down to CS4, I don't know what version you use:

    http://www.filehorde.com/o/Index_Fix_CS4.zip

     

    Consider centralizing the code to external AS files and then importing those. It's a huge PITA to go into someones project who has code sprinkled all over frames hidden in clips. Some of your code is 100% identical in separate clips so if you change anything (like I did) I had to change the frame scripts in both areas.. You're making it hard on yourself.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 21, 2012 7:19 PM   in reply to prashant.savalia1

    All that you dream of and more can be accomplished. Just not off agency time. Play with it and any methods used that you're unfamiliar with please read up on. Cya Monday

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points