2 Replies Latest reply on Jun 30, 2007 4:36 AM by Peter Lorent

    Some help with my class

    quovadimus02
      I'm making a class for an image viewer movieclip. Right now the movieclip sits on the main timeline and is called fullSizeViewer_mc, the linkage identifier as well as the class name is fullSizeViewer. The only thing in the movieclip is another clip called bg_mc. This clip is supposed to function similar to a "lightbox". bg_mc fades in covering the entire stage, an image is loaded above it. when a user clicks on bg_mc it calls a function (fadeOut) to remove the clip picHolder_mc and fade out. my function is being called because my trace statement in it fires, but bg_mc is not fading out and I'm unable to remove the picHolder_mc clip.

      This is really my first dive into OOP so any help here would be appreciated.

        • 1. Re: Some help with my class
          quovadimus02 Level 1
          Anyone got any ideas?
          • 2. Re: Some help with my class
            Peter Lorent Level 2
            Two things, no three, wait! four...

            private function fadeOut():Void {
            trace("wtf?");
            bgFade = new Tween(this, "_alpha", Regular.easeOut, 100, 0, .5, true);
            imageFade = new Tween(_parent.picHolder_mc, "_alpha", Regular.easeOut, 100, 0, .5, true);
            removeMovieClip(_parent.picHolder_mc);
            }

            fadeOut gets executed in the scope of bg_mc -> bg_mc.onRelease = fadeOut;

            So you need to refer to this in the following line
            bgFade = new Tween(this, "_alpha", Regular.easeOut, 100, 0, .5, true);

            Since picHolder_mc exists in the timeline of fullsizeviewer (the _parent):
            imageFade = new Tween(_parent.picHolder_mc, "_alpha", Regular.easeOut, 100, 0, .5, true);

            and consequently
            _parent.removeMovieClip(picHolder_mc);

            but, that last line gets executed right away without waiting for the tween to finish. You need to use a listener on the tween to achieve that.

            private function fadeOut():Void {
            trace("wtf?");
            bgFade = new Tween(this, "_alpha", Regular.easeOut, 100, 0, .5, true);
            imageFade = new Tween(_parent.picHolder_mc, "_alpha", Regular.easeOut, 100, 0, .5, true);
            imageFade.onMotionFinished=function():Void{
            _parent.removeMovieClip(picHolder_mc);
            }
            }

            Last but not least: when extending MovieClip in AS2, you shouldn't be using a constructor but an onLoad

            public function onLoad() {
            this.swapDepths(_root.getNextHighestDepth());
            bg_mc._width = Stage.width;
            bg_mc._height = Stage.height;
            bg_mc._x = 0;
            bg_mc._y = 0;
            bg_mc._alpha = 0;
            }