Skip navigation
moloh12345
Currently Being Moderated

scroll xml thumbnail grid by arrows

Sep 5, 2012 3:24 PM

Tags: #xml #actionscrip3 #scrolling_images

Hi


I'm new on this forum


 

I've got xml thumbnail grid, i creaded mask for it and now i want to scroll the grid but don't have idea how.


I wan't to have two arrows previous and next to scroll my thumbnail grid to next column.


here is my code :

 

 

import flash.net.URLLoader;

import flash.net.URLRequest;

import flash.events.Event;

import flash.display.MovieClip;

import flash.display.Loader;

import flash.events.MouseEvent;

import flash.display.Sprite;

 

 

 

var rows:Number;

var columns:Number;

var my_x:Number;

var my_y:Number;

var my_thumb_width:Number;

var my_thumb_height:Number;

var my_images:XMLList;

var my_total:Number;

 

var container_mc:MovieClip;

//maska

var mask_mc:Sprite;

var maskHeight:int = (my_thumb_height+10)*y_counter;

var maskWidth:int = (my_thumb_width+10) *3 ;

 

 

var x_counter:Number = 0;

var y_counter:Number = 0;

 

 

 

 

var myXMLLoader:URLLoader = new URLLoader();

myXMLLoader.load(new URLRequest("gallery.xml"));

myXMLLoader.addEventListener(Event.COMPLETE, processXML);

 

 

 

 

 

function processXML(e:Event):void

{

   var myXML:XML = new XML(e.target.data);

   columns = myXML. @ COLUMNS;

   rows = myXML. @ ROWS;

   my_x = 20;

   my_y = 20;

   my_thumb_width = myXML. @ WIDTH;

   my_thumb_height = myXML. @ HEIGHT;

   my_images = myXML.IMAGE;

   my_total = my_images.length();

  

   createContainer();

   callThumbs();

   createMask();

  

 

 

}

 

function createContainer():void

{

   container_mc = new MovieClip();

   container_mc.x = my_x;

   container_mc.y = my_y;

   container_mc.buttonMode = true;

   container_mc.addEventListener(MouseEvent.MOUSE_OVER, onOver);

   container_mc.addEventListener(MouseEvent.MOUSE_OUT, onOut);

   addChild(container_mc);

}

function createMask():void{

   mask_mc  = new Sprite();

   mask_mc.graphics.beginFill(0x000000);

   mask_mc.graphics.drawRect(0,0,(my_thumb_width+10)*columns,(my_thumb_h eight+10)*rows);

   mask_mc.x = my_x;

   mask_mc.y = my_y;

   addChild(mask_mc);

   container_mc.mask = mask_mc;  

   mask_mc.cacheAsBitmap = true;

   container_mc.cacheAsBitmap = true;

  

}

 

 

 

function callThumbs():void

{

   for (var i:Number = 0; i < my_total; i++)

   {

 

      var thumb_url = my_images[i]. @ image;

      var thumb_loader = new Loader();

      thumb_loader.load(new URLRequest(thumb_url));

      thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded);

 

      thumb_loader.x = (my_thumb_width+10)*x_counter;

      thumb_loader.y = (my_thumb_height+10)*y_counter;

 

      if (y_counter + 1 < rows)

      {

         y_counter++;

      }

      else

      {

         y_counter = 0;

         x_counter++;

      }

   }

 

}

function thumbLoaded(e:Event):void

{

   var my_thumb:Loader = Loader(e.target.loader);

   container_mc.addChild(my_thumb);

}

 

arrowLeft.addEventListener(MouseEvent.CLICK,leftClick);

arrowRight.addEventListener(MouseEvent.CLICK,rightClick);

 

function leftClick(MouseEvent):void{

 

}

 

function rightClick(MouseEvent):void{

 

}

 

 

And now i don't have an idea how to move my thumbnail grid after click to arrow to next column or previous column.

I need to add something here but i don't know what:

 

 

arrowLeft.addEventListener(MouseEvent.CLICK,leftClick);

arrowRight.addEventListener(MouseEvent.CLICK,rightClick);

 

function leftClick(MouseEvent):void{

 

}

 

function rightClick(MouseEvent):void{

 

}

 

 

Please help !!!

 

Greetings.

 

 


 
Replies
  • Currently Being Moderated
    Sep 5, 2012 6:37 PM   in reply to moloh12345

    What you do with those functions depends on how you want things to scroll.  For starters you can just try using something like the following, and after you see what it does then you might be able to think about what you really want it to do.

     

    arrowLeft.addEventListener(MouseEvent.CLICK,leftClick);

    arrowRight.addEventListener(MouseEvent.CLICK,rightClick);

     

    function leftClick(MouseEvent):void{

        container_mc.x += 100;  // arbitrarily chose 100 pixels

    }

     

    function rightClick(MouseEvent):void{

        container_mc.x -= 100; 

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 6, 2012 4:34 AM   in reply to moloh12345

    Your first posting should have offered the detail your second posting does... that is why my response offered only a basic solution. 

     

    If you images are all different widths, because of your desire to base the amount of scrolling on how many times you click, it will be necessary to store the location of each image in an array and use a counter to keep track of the clicks.  That counter will coincide with the index of the array.  So if you start at 0 clicks, when you have clicked three times you will go to the location designated by the x value defined in the array at index 3.

     
    |
    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