views:

10

answers:

0

Hi all,

Newbie here but seen alot of help come from this site so here goes.

I am trying to create a thumbnail slide to add to my gallery but something is not right. the code follows. Any help would be appreciated.

 package  {
import flash.display.Sprite;
import flash.display.MovieClip;

import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;



    public class thumbnailslider extends MovieClip {

        public var thumbnail:Sprite;
        public var interfaceThumbsContainer:Sprite;

            private static var instance:thumbnailslider;
            public var thumbs:Array;


    //----------------------------------    
    public static function getInstance():thumbnailslider
    //----------------------------------    
    {
        return thumbnailslider.instance;
    }


    //Class constructor
    //----------------------------------    
    public function thumbnailslider():void {
    //----------------------------------
        this.addEventListener(Event.ENTER_FRAME, startApplication); //delay by one frame to have the stage always
    }



    //Start the main application
    //----------------------------------    
    public function startApplication(e:Event):void {
    //----------------------------------
        if (stage!=null)
        {
            this.removeEventListener(Event.ENTER_FRAME, startApplication);

            this.addEventListener(Event.ENTER_FRAME, initApp);

        }
    }




    //Preload application
    //----------------------------------    
    public function initApp(e:Event):void {
    //----------------------------------    
        thumbnailslider.instance = this;

        thumbs = new Array();
        var b;
        var thumbsHolder:Sprite = new Sprite();
for (b=0; b<10; b++)
        {
            thumbs[b] = new Sprite();
            thumbs[b].graphics.beginFill(0xCCFF00);
            thumbs[b].graphics.drawRect(b*95, 65, 45, 45);
            thumbsHolder.addChild(thumbs[b]);

        }       

        interfaceThumbsContainer= new Sprite();

        if (!this.contains(interfaceThumbsContainer)) this.addChild(interfaceThumbsContainer);
        if (!interfaceThumbsContainer.contains(thumbsHolder)) interfaceThumbsContainer.addChild((thumbsHolder));
        interfaceThumbsContainer.y=437;
        interfaceThumbsContainer.x=0;
        interfaceThumbsContainer.addEventListener(MouseEvent.MOUSE_OVER ,initScroll);





    }


public function initScroll(event:Event):void {  

            var thumbMask:Sprite = new Sprite
            thumbMask.graphics.beginFill(0xCCFF00);
            thumbMask.graphics.drawRect(interfaceThumbsContainer.x,interfaceThumbsContainer.y,interfaceThumbsContainer.width,interfaceThumbsContainer.height);
interfaceThumbsContainer.mask=thumbMask;



        if (thumbMask.mouseX<(thumbMask.height*(1/3)) || thumbMask.mouseX>(thumbMask.height*(2/3)) && thumbMask.mouseX<(45) ) {
            interfaceThumbsContainer.x += Math.cos(((thumbMask.mouseX)/thumbMask.height)*Math.PI)*10;

            if (interfaceThumbsContainer.x>thumbMask.x) {
                interfaceThumbsContainer.x = thumbMask.x;
            }

            if (interfaceThumbsContainer.x<(thumbMask.x-(interfaceThumbsContainer.height-thumbMask.height))) {
            interfaceThumbsContainer.x = thumbMask.x-(interfaceThumbsContainer.height-thumbMask.height);
            }
        }

}


    }

}