7 Replies Latest reply on Aug 22, 2011 7:19 PM by freakyword

    ScrollPane doesn't display its content

    freakyword Level 1

      I created a scrollpane in as3 and set its source to another object, which contains several rows of icons.

      The scrollbar in the scrollpane is getting the right length, which means the object was loaded as expected, but the contant is not showing correctly.

       

      I created a Thumbnail class for this file to load and make each individual thumbnail.

      Here is my code, the red text is where each thumbnail is loaded:

       

      import fl.containers.UILoader;
      import caurina.transitions.*;
      import flash.events.Event;
      import fl.containers.ScrollPane;

       

      var urlRequest:URLRequest = new URLRequest("pics.xml");
      var urlLoader:URLLoader = new URLLoader();
      var myXML:XML = new XML();
      var xmlList:XMLList;
      myXML.ignoreWhitespace = true;
      urlLoader.addEventListener(Event.COMPLETE,fileLoaded);
      urlLoader.load(urlRequest);

      var arrayURL:Array = new Array();

      var arrayName:Array = new Array();

      var holderArray:Array = new Array();

      var nrColumns:uint = 3;

      var sprite:Sprite = new Sprite();
      addChild(sprite);
      var thumb:Thumbnail;

      var thumbsHolder:Sprite = new Sprite();
      sprite.addChild(thumbsHolder);

      var loaderHolder:Sprite = new Sprite();
      loaderHolder.graphics.beginFill(0x666666,1);
      loaderHolder.graphics.drawRoundRect(0,0,450,340, 20,20);
      loaderHolder.graphics.endFill();
      loaderHolder.x = 280;
      loaderHolder.y = 240;
      sprite.addChild(loaderHolder);

      var photoLoader:UILoader = new UILoader();
      photoLoader.width = 450;
      photoLoader.height = 340;
      photoLoader.y = 5;
      photoLoader.x = 5;
      photoLoader.buttonMode = true;
      photoLoader.addEventListener(MouseEvent.CLICK,onClickBack);
      loaderHolder.addChild(photoLoader);

       

      var scrollPane:ScrollPane=new ScrollPane();
      var skin:MovieClip = new MovieClip();
      scrollPane.x = 805;
      scrollPane.y = 405;
      scrollPane.width = 215;
      scrollPane.height = 280;

      scrollPane.setStyle( "skin", skin );

      scrollPane.setStyle( "upSkin", skin );

      scrollPane.source = thumbsHolder;
      sprite.addChild(scrollPane);

       

      function fileLoaded(event:Event):void
      {

      myXML = XML(event.target.data);
      xmlList = myXML.children();
      for (var i:int=0; i<xmlList.length(); i++)
      {
        var picURL:String = xmlList[i].url;
        var picName:String = xmlList[i].big_url;
        arrayURL.push(picURL);
        arrayName.push(picName);
        holderArray[i] = new Thumbnail(arrayURL[i],i,arrayName[i]);
        holderArray[i].addEventListener(MouseEvent.CLICK,onClick);
        holderArray[i].name = arrayName[i];
        holderArray[i].buttonMode = true;
        if (i<nrColumns)
        {
         holderArray[i].y = 440;
         holderArray[i].x = i * 65 + 840;
        }
        else
        {
         holderArray[i].y = holderArray[i - nrColumns].y + 65;
         holderArray[i].x = holderArray[i - nrColumns].x;
        }
        thumbsHolder.addChild(holderArray[i]);
        scrollPane.update();
      }
      }

      function onClick(event:MouseEvent):void
      {
      photoLoader.alpha = 0.1;
      photoLoader.source = event.currentTarget.name;
      photoLoader.addEventListener(Event.COMPLETE, fadeOut);
      function fadeOut(event:Event):void
      {
        Tweener.addTween(photoLoader, {alpha:1, time:0.5, transition:"linear"});
      }
      }

      function onClickBack(event:MouseEvent):void
      {
        Tweener.addTween(loaderHolder, {alpha:.5, time:2, transition:"linear"});
      }