控制每个循环的Foor索引

时间:2011-10-12 13:27:48

标签: actionscript-3

我试过这个:

PHP:

<?PHP

$link = mysql_connect("localhost","root","");
mysql_select_db("dbname");

$query = "SELECT * FROM dress where dress_type='shirts' AND sex='male'";
$results = mysql_query($query);

while($row = mysql_fetch_assoc($results))
            {  { $path = $row["imagelocation"]; echo $path . "#";

    }

    mysql_close($link);

?>

AS3:

var ldr:URLLoader = new URLLoader( new URLRequest("your_php_file.php") );

ldr.addEventListener(Event.COMPLETE, _done); function _done(e:Event):void { ldr.removeEventListener(Event.COMPLETE, _done);

var ar:Array = String(e.target.data).split("#");

for each(var i:String in ar)
{
    var img:Loader = new Loader();
    img.load(new URLRequest(i));

    addChild(img);
}

}

如何控制每个循环中的字符串?

1 个答案:

答案 0 :(得分:0)

如果你也想索引,为什么不使用常规for循环?它更简单,编码和执行速度更快

根据第一条评论进行修改:

for (var x:int=0; x<ar.length; x++)
{
    var i:String=ar[x];
    var img:Loader = new Loader();
    img.load(new URLRequest(i));

    addChild(img);
}