Skip to main content
August 23, 2011
Question

Can't wrap-around scrolling slideshow

  • August 23, 2011
  • 1 reply
  • 446 views

Hello! I'm trying to make a scrolling slideshow. They are real estate listings read from an XML file which consist of a thumbnail and 3 text fields (Title, address, price). Right now I have it working to the point where all of the data loads into a row of MCs that scroll to the left using the Tweener class. I just can't achieve a wrap around effect. Here's a link to the swf as it is now: http://dl.dropbox.com/u/7566017/ticker.swf

Knowing that duplicating MCs is a difficult task, I just half-assed it by loading the dame data into a new array of MCs (arrayBox and arrayBox2). The code below does not actually make use of the "duplicated" listing MCs. I thought I could just move a listing MC over to the right after when totally offstage but that does not seem to be working.

Here's the offending AS3 source:

function urlLoaded(event:Event):void {

     xml = XML(event.target.data);

     var listingsXML:XML = XML(urlLoader.data);

     var xmlDoc:XMLDocument = new XMLDocument();

     xmlDoc.ignoreWhite = true;

     xmlDoc.parseXML(listingsXML.toXMLString());

    

     for each (var prop:XML in xml.listing)

     {

          var listingBox:MovieClip =  new MovieClip();

          var thumb:Thumbnail = new Thumbnail(prop.url.toString()); //Thumbnail is a custom class that uses the Loader() class

          var bldgName:TextField = new TextField();

          var address:TextField = new TextField();

          var price:TextField = new TextField();

          bldgName.defaultTextFormat = format1;

          bldgName.text = prop.name.toString();

          bldgName.width = 200;

          address.defaultTextFormat = format1;

          address.text = prop.address.toString();

          address.width = 200;

          price.defaultTextFormat = format1;

          price.text = prop.price.toString();

          price.width = 200;

         

          thumb.x = 0+(listings*210);

          thumb.y = 1;

          bldgName.x = 0+(listings*210);

          bldgName.y = 150;

          address.x = 0+(listings*210);

          address.y = 170;

          price.x = 0+(listings*210);

          price.y = 190;

         

          listingBox.addChild(thumb);

          listingBox.addChild(bldgName);

          listingBox.addChild(address);

          listingBox.addChild(price);

         

         

          arrayBox[listings] = listingBox;

          listings++;

     }

     for each (var prop2:XML in xml.listing)

     {

          var listingBox2:MovieClip =  new MovieClip();

          var thumb2:Thumbnail = new Thumbnail(prop2.url.toString());

          var bldgName2:TextField = new TextField();

          var address2:TextField = new TextField();

          var price2:TextField = new TextField();

          bldgName2.defaultTextFormat = format1;

          bldgName2.text = prop2.name.toString();

          bldgName2.width = 200;

          address2.defaultTextFormat = format1;

          address2.text = prop2.address.toString();

          address2.width = 200;

          price2.defaultTextFormat = format1;

          price2.text = prop2.price.toString();

          price2.width = 200;

         

          thumb2.x = 0+(listings*210);

          thumb2.y = 0;

          bldgName2.x = 0+(listings*210);

          bldgName2.y = 150;

          address2.x = 0+(listings*210);

          address2.y = 170;

          price2.x = 0+(listings*210);

          price2.y = 190;

          trace(thumb2.x);

         

          listingBox2.addChild(thumb2);

          listingBox2.addChild(bldgName2);

          listingBox2.addChild(address2);

          listingBox2.addChild(price2);

         

         

          arrayBox2[count] = listingBox2;

          listings++;

          count++;

     }

     for each (var box:MovieClip in arrayBox)

     {

          addChild(box);

     }

     for each (var box0:MovieClip in arrayBox2)

     {

          addChild(box0);

     }

     trace("timer start");

     timer1.start();

    

}

function startScroll(e:TimerEvent):void

{

     var i:Number;

     if (arrayBox.length>3) {

     for each (var box:MovieClip in arrayBox)

     {

          if (box.x>-210) {

               Tweener.addTween(box, {x:(box.x-210), transition:"easeOutCubic",time:0.8});

               trace("slide",box.x.toString());

          }

          else {

               trace("wrap",box.x.toString());

               box.x = 610;

          }

     }

     }

}

I thought I coded it so the "box" MC would move over to the right after it goes offstage but it moves all of the boxes at once. Any assistance at all would be much appreciated. Thanks!

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
August 23, 2011

The problem lies in how you are setting the positions of the contents inside the listingBox objects instead of positioning the lisingBox objects themselves. All of the listingBox objects are being placed at x = 0, so they all reach -210 at the same time.  The stuff inside them is what is being spread out by 210 spacing for each step in the loop.

August 24, 2011

I just added

listingBox.x = 0+(listings*210); listingBox.y = 1;

Before all of the other positioning and removed the positioning of the inner objects and it works fine now. Thank you!

I should have marked his reply as the answer rather than "helpful."

Ned Murphy
Legend
August 24, 2011

You're welcome