5 Replies Latest reply on Dec 19, 2008 9:31 AM by Ned Murphy

    Linking buttons

    davey_darch
      I'm currently working on a scene with an image loader that is linked to a series of buttons and their individual instance names. I have now placed these buttons within a cursor controlled image scroller (still within the same scene) however now the image loader can no longer read the buttons' instances in order to load the relevant images onscreen. Instead it reads the movies' instance. If anyone can help I would be very grateful.
        • 1. Re: Linking buttons
          Ned Murphy Adobe Community Professional & MVP
          Describe how the image scroller with the buttons is designed and show the code that is used to control it.
          • 2. Linking buttons
            davey_darch Level 1
            The scroller is made up from two main movieclips;
            "menu" in which I have grouped all of the buttons.
            "content" a controlling movieclip that is contained just outside of the stage. This is the coding from the first frame of that movie clip.

            //setting the variables for the script;
            _root.scrollerName = _root.menu;
            _root.left = 474;
            _root.innerLeft = 494;
            _root.right = 884;
            _root.innerRight = 864;
            _root.top = 232;
            _root.bottom = 314;
            _root.minXposition = -260;
            _root.maxXposition = 266;
            _root.idleScrollSpeed = 0;
            _root.overScrollSpeed = 10;
            //if the scroller has gone to the end, switch directions;
            if (_root.scrollerName._x < _root.minXposition) {
            _root.scrollerDirection = "right";
            } else if (_root.scrollerName._x > _root.maxXposition) {
            _root.scrollerDirection = "left";
            }
            if (_root._ymouse < _root.bottom && _root._ymouse > _root.top) {
            //checking to see if the mouse is in the left area, if so, continue;
            if (_root._xmouse > _root.left && _root._xmouse < _root.innerLeft) {
            if (_root.scrollerName._x > _root.maxXposition) {
            break;
            } else {
            _root.scrollerName._x = _root.scrollerName._x + _root.overScrollSpeed;
            }
            } else if (_root._xmouse > _root.innerRight && _root._xmouse < _root.right) {
            if (_root.scrollerName._x < _root.minXposition) {
            break;
            } else {
            _root.scrollerName._x = _root.scrollerName._x - _root.overScrollSpeed;
            }
            } else if (_root._xmouse < _root.left or _root._xmouse > _root.right) {
            if (_root.scrollerDirection == "right") {
            _root.scrollerName._x = _root.scrollerName._x + _root.idleScrollSpeed;
            } else if (_root.scrollerDirection == "left") {
            _root.scrollerName._x = _root.scrollerName._x - _root.idleScrollSpeed;
            }
            }
            } else if (_root.scrollerDirection == "right") {
            _root.scrollerName._x = _root.scrollerName._x + _root.idleScrollSpeed;
            } else if (_root.scrollerDirection == "left") {
            _root.scrollerName._x = _root.scrollerName._x - _root.idleScrollSpeed;
            }

            The second frame contains this piece of coding

            gotoAndPlay(1);
            • 3. Re: Linking buttons
              Ned Murphy Adobe Community Professional & MVP
              Okay, so it appears as though the content clip doesn't interfere with the menu. It merely reads the mouse position and moves the menu accordingly. That's one thing out of the way, though there is alot of excess code there that could go away.

              The use of _root all over the place is unnecessary if they are variables that only reside in that movie. Break statements don't apply to if/else conditionals, they are for ending loops and for getting out of switch statements. So you could eliminate some lines by changing the conditional logic.

              The next thing that needs to be looked at is the code that the buttons use and whatever code/function they deal with in terms of loading content. CAn you show that?
              • 4. Re: Linking buttons
                davey_darch Level 1
                Hi Ned

                In terms of actual code on the buttons themselves there is none, only instances that the image loader relates to with the following code.

                imgbtn1.onRelease = function() {
                infoField._visible = true;
                startLoading("picture1.jpg");
                };
                imgbtn2.onRelease = function() {
                infoField._visible = true;
                startLoading("picture2.jpg");
                };
                imgbtn3.onRelease = function() {
                infoField._visible = true;
                startLoading("picture3.jpg");
                };
                imgbtn4.onRelease = function() {
                infoField._visible = true;
                startLoading("picture4.jpg");
                };
                function startLoading(whichImage) {
                loadMovie(whichImage, "imageLoader");
                _root.onEnterFrame = function() {
                infoLoaded = imageLoader.getBytesLoaded();
                infoTotal = imageLoader.getBytesTotal();
                percentage = Math.floor(infoLoaded/infoTotal*100);
                infoField.text = percentage+"%";
                if (percentage>=100) {
                delete this.onEnterFrame;
                infoField._visible = false;
                }
                };
                }

                So the problem I have now is that the image loader can not read these instances because they are contained in the movieclip "menu" with its instance name which is needed in order for it work. Thus blocking the original buttons and their instances.

                • 5. Linking buttons
                  Ned Murphy Adobe Community Professional & MVP
                  Good to see you're not putting code on buttons!

                  I have to wonder what's going on with that imageLoader. From what I know, loadMovie can't provide a loading status, but loadClip can. So you may want to switch to using loadClip instead. That way you have something you can definitely monitor for the loading process.

                  Since imageLoader would be the target of the loading, it's likely a movieclip, and by itself it is completely loaded I would think. So your enterFrame function is probably being deleted before anything starts to load.

                  I'm also not sure about defining functions within functions. I've never taken such an approach, so that's the most I can say.

                  Try commenting out that entire onEnterFrame function code in that function and see if your movie loads as desired... less the percentage reporting part.