Greetings again,
i have this AS2.0 gridlayout code i once wrote, which works perfectly
but since i am trying to learn AS3.0 some things aren’t clear for me.
first off all:
how comes my iteration of the next/previous batch doesn’t work:
it seems it cast succesfuly the first 4 items, and the “next” button appears, yet
when you click on it. the nextbatch function triggers, but the "previous button does not appear. this does! work when i put in the for loop instead of increment = my_total.length
but then ofcourse i see all items from the xml instead of my desired increment
secondly:
how do i clear my casted items, so that the results are updated? and thus my clips don’t get stacked on the stage.
see the clearMenu() function for this.
heres my code, if needed i’ll post the source, if this is too abstract.
I am sure i am overlooking some silly things here again, as the code nearly works like a charm, just the two pointers i mentioned.
Thanks in advance
import caurina.transitions.*;
//variables
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 spacingX:Number = 5;
var spacingY:Number = 5;
var currentItems:Number = 0;
var increment:Number = 4;
var container_mc:MovieClip;
function loadXML ():void
{
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load (new URLRequest("xml_gallery02.xml"));
myXMLLoader.addEventListener (Event.COMPLETE,processXML);
}
function processXML (e:Event):void
{
//
var myXML:XML = new XML(e.target.data);
columns = myXML. @ COLUMNS;
my_x = myXML. @ XPOSITIONS;
my_y = myXML. @ YPOSITIONS;
my_thumb_width = myXML. @ WIDTH;
my_thumb_height = myXML. @ HEIGHT;
my_images = myXML.IMAGE;
createContainer ();
callThumbs ();
}
function createContainer ():void
{
//
container_mc = new MovieClip();
container_mc.x = my_x;
container_mc.y = my_y;
addChild (container_mc);
container_mc.buttonMode = true;
container_mc.addEventListener (MouseEvent.CLICK, callFull);
}
function clearMenu ()
{
for (var i in container_mc)
{
//
if (container_mc* is MovieClip)
{
container_mc*.removeChild ();
trace ("clearing");
}
}
}
function callThumbs ():void
{
clearMenu ();
var i:Number;
var xMax:Number = 1003;
var iX:Number = 0;
var iY:Number = 60;
for (i = currentItems; i < increment; i++)
{
var thumb_url = my_images*. @ THUMB;
var thumb_loader = new Loader();
thumb_loader.load (new URLRequest(thumb_url));
thumb_loader.contentLoaderInfo.addEventListener (Event.COMPLETE, thumbLoaded);
thumb_loader.name = i;
if (i<(currentItems+increment))
{
if (currentItems >= increment)
{
prevbtn.visible = true;
}
else
{
prevbtn.visible = false;
}
if ((my_total - currentItems)>increment)
{
nextbtn.visible = true;
}
else
{
nextbtn.visible = false;
}
}
if (iX < xMax)
{
thumb_loader.x = iX;
thumb_loader.y = iY;
iX += my_thumb_width + spacingX;
}
else
{
iY+=my_thumb_height+spacingY;
iX=0;
thumb_loader.x=iX;
thumb_loader.y=iY;
iX+=my_thumb_width+spacingX;
}
nextbtn.buttonMode=true;
prevbtn.buttonMode=true;
nextbtn.addEventListener (MouseEvent.CLICK, nextBatch);
prevbtn.addEventListener (MouseEvent.CLICK, prevBatch);
}
}
function thumbLoaded (e:Event):void
{
var my_thumb:Loader=Loader(e.target.loader);
container_mc.addChild (my_thumb);
}
function callFull (e:MouseEvent):void
{
//
var full_loader:Loader = new Loader();
var full_url=my_images[e.target.name].@FULL;
full_loader.load (new URLRequest(full_url));
full_loader.contentLoaderInfo.addEventListener (Event.INIT, fullLoaded);
container_mc.removeEventListener (MouseEvent.CLICK, callFull);
}
function fullLoaded (e:Event):void
{
var my_loader:Loader=Loader(e.target.loader);
addChild (my_loader);
my_loader.x = (stage.stageWidth - my_loader.width)/2;
my_loader.y = (stage.stageHeight - my_loader.height)/2;
my_loader.addEventListener (MouseEvent.CLICK,removeFull);
}
function removeFull (e:MouseEvent):void
{
var my_loader:Loader=Loader(e.currentTarget);
my_loader.unload ();
removeChild (my_loader);
container_mc.addEventListener (MouseEvent.CLICK, callFull);
}
function nextBatch (e:Event):void
{
trace ("nextbatch");
currentItems+=increment;
loadXML ();
}
function prevBatch (e:Event):void
{
trace ("prevbatch");
currentItems-=increment;
loadXML ();
}
nextbtn.visible=false;
prevbtn.visible=false;
loadXML ();