Skip to main content
Known Participant
August 4, 2009
Answered

For loop acting up, images scale and are missplaced

  • August 4, 2009
  • 2 replies
  • 766 views

I have an image which i am attaching, it is the white portion of the image( i saved it on a black background so it is easy to see, but it is on a transparent background saved as a gif and imported to flash). When my for loop runs, i am trying to position this image on stage programatically, but it seems as it is not doing it right. It scales the image, and positions some all over the place

I wanted the images (8 of them) to appear in 2 colums each one spaced out evenly, but it fails to do that. The movie clip holds the image below. Also since it is a irregular shape, it seems to make the edges look really rought.

1) Why is the for loop generating these images all over the place like that?

2) Would it be more ideal to draw this shape with flash, rather then using a gif image? Is such a shape even possible to draw?

This is the code:

import fl.transitions.*;
import fl.transitions.easing.*;
import flash.events.TimerEvent;

var imageLoader:Loader;

var xmlData:XML;

var bucketItem:MovieClip; //These hold the image attached below
var bucketHor:MovieClip;

placeBuckets();

function set loadedXML(xml:XML):void {
    xmlData = xml;
}

function placeBuckets():void {
    var firstY:Number = 50;
    var secondY:Number = 115;
   
    var bucketCount:XMLList = xmlData.product;
    for (var u:uint = 0; u < bucketCount.length(); u++) {
    bucketItem = new bucket();
    bucketHor = new bucketr();
   
    if (bucketCount.country.text() == "USA") {   
    bucketItem.y = firstY;
    bucketItem.x = 100;
    //var bucketTween:Tween = new Tween(bucketItem, "x", Regular.easeOut, 0, bucketItem.x, 0.5, true);
    } else {
    bucketHor.y = secondY;   
    bucketHor.x = 300;
    //bucketItem.scaleX = -1;
    //var buckettwoTween:Tween = new Tween(bucketItem, "x", Regular.easeOut, 0, bucketItem.x, 0.5, true);
    }
    var bucketImgTrans = new TransitionManager(bucketItem);
    bucketImgTrans.startTransition({type:Zoom, direction:Transition.IN, duration:3, easing:Strong.easeOut});
    var bucketImgTransH = new TransitionManager(bucketHor);
    bucketImgTransH.startTransition({type:Zoom, direction:Transition.IN, duration:3, easing:Strong.easeOut});   
    trace(bucketItem.y);

     trace(bucketHor.y);
    addChildAt(bucketItem, 0);
    addChildAt(bucketHor, 0);
    secondY = (secondY + 200) - 115;
    firstY     = (firstY  + 130) -  50;   
    }
}

This is the trace Stmt for both Bucket y position

0
115
0
200
0
285
0
370
370
0
450
0
530
0
610
0

This topic has been closed for replies.
Correct answer Andrei1-bKoviI

As for drawing graphic here is the code (not exactly like yours but you can make adjustments - read about Graphics class in Flash documentation):

var sp:Sprite = new Sprite();
var gr:Graphics = sp.graphics;
gr.beginFill(0xff0000);
gr.moveTo(0, 0);
gr.lineTo(213, 5);
gr.lineTo(213, 65);
gr.lineTo(6, 75);
gr.lineTo(0, 0);
gr.endFill();
addChild(sp);

As for the positioning, what are these backet and baketr classes/symbols?

 


2 replies

Inspiring
August 4, 2009

Also a tip.

When you are positioning objects in rows and columns it is very efficient to use modulo operator (%). For instance (watch traces):

In this example it calculates rows and columns when you want to place 14 objects in three columns:

 
// number of columns var numColumns:int = 3; var row:int = 0; var column:int = 0; for (var i:int = 0; i < 14; i++) {      // calculate row number      row = int((i / numColumns));      // use modulo to calculate column number      column = i % numColumns;      trace("i = " + i  + " ::  row =  " + row  + " :: column = " + column); }

You can adjust x/y positions bases on row/column values.

georgeebAuthor
Known Participant
August 4, 2009

the bucket movieclips are essentially those images placed into buckets, the for loop does a bad job positioning them, that's why i was wondering why the trace stmt was so off the rocker.

That is a great mock of my image, but the edges are really rough, is there a way around making it smoother, perhaps a filter or something?

Thank you

georgeebAuthor
Known Participant
August 4, 2009

resolved the loop problem by using a class as suggested by Andrei in the previous post

Thanks

Andrei1-bKoviICorrect answer
Inspiring
August 4, 2009

As for drawing graphic here is the code (not exactly like yours but you can make adjustments - read about Graphics class in Flash documentation):

var sp:Sprite = new Sprite();
var gr:Graphics = sp.graphics;
gr.beginFill(0xff0000);
gr.moveTo(0, 0);
gr.lineTo(213, 5);
gr.lineTo(213, 65);
gr.lineTo(6, 75);
gr.lineTo(0, 0);
gr.endFill();
addChild(sp);

As for the positioning, what are these backet and baketr classes/symbols?