针对循环问题的AS3 URLRequest

时间:2010-06-11 23:20:52

标签: for-loop actionscript-3 urlrequest

我从xml文件中读取了一些数据,除了网址之外,一切都很好用。我无法想象“navigateURL”函数或eventListener的问题...我点击它的哪个方格打开了xml文件中的最后一个网址

for(var i:Number = 0; i <= gamesInput.game.length() -1; i++)
 {
  var square:square_mc = new square_mc();

  //xml values
  var tGame_name:String   = gamesInput.game.name.text()[i];//game name
  var tGame_id:Number     = gamesInput.children()[i].attributes()[2].toXMLString();//game id
  var tGame_thumbnail:String  = thumbPath + gamesInput.game.thumbnail.text()[i];//thumb path
  var tGame_url:String     = gamesInput.game.url.text()[i];//game url

  addChild(square);
  square.tgname_txt.text = tGame_name;
  square.tgurl_txt.text = tGame_url;

  //load & attach game thumb
  var getThumb:URLRequest = new URLRequest(tGame_thumbnail);
  var loadThumb:Loader = new Loader();
   loadThumb.load(getThumb);
   square.addChild(loadThumb);
  //
  square.y = squareY;
  square.x = squareX;
  squareX += square.width + 10;

  square.buttonMode = true;
  square.addEventListener(MouseEvent.CLICK, navigateURL);

 }

 function navigateURL(event:MouseEvent):void
 { 
  var url:URLRequest = new URLRequest(tGame_url);
  navigateToURL(url, "_blank");
  trace(tGame_url);
 }

非常感谢!

4 个答案:

答案 0 :(得分:1)

在navigateURL()中你使用tGame_url,但我认为你宁愿使用像tgurl_txt.text这样的东西,每个方格都不同。

答案 1 :(得分:0)

看起来你没有正确地附加事件监听器。而不是this.addEventListener,将它附加到您在创建新square_mc时创建的变量.....所以:

square.addEventListener(MouseEvent.CLICK,navigateURL);

答案 2 :(得分:0)

你应该在Squares上添加addEventListener

mmm ..还要确定eventhandler函数如何获得正确的tgame_url var。

如果您尝试这样做怎么办:

 square.addEventListener(MouseEvent.CLICK, function navigateURL(event:MouseEvent):void 
 {  
    var url:URLRequest = new URLRequest(tGame_url); 
     navigateToURL(url, "_blank"); 
    trace(tGame_url); 
  });

答案 3 :(得分:0)

试着追踪这个:

function navigateURL(event:MouseEvent):void
 { 
  var url:URLRequest = new URLRequest(tGame_url);
  navigateToURL(url, "_blank");
  //trace(tGame_url);
  trace(event.currentTarget.tgurl_txt.text);
 }

你应该在循环中将你的网址添加到你的方块

square.theUrl = tGame_url;

在事件监听器功能中,您应该可以使用

访问它
event.currentTarget.theUrl;