English 中文(简体)
i++在AS3中不可行?
原标题:i++ does not work for var in AS3?

我正试图从一片 lo中接过多个var。 ur:

Total=2&id1=2&content1=I+am+1+blog&id2=4&content2=I+am+2+blog

for (var i:Number=i; i<=total;i++){ 
 trace(i);
 var id = this.evt.target.data+i;
        var content = evt.target.data.content;
 trace ( id from DB:   + id);
        trace ( content from DB:   + content);
}

这条法典赢得了一定的工作。 我尝试了各种方式:

var id = this.evt.target.data+i;
var id = ["this.evt.target.data"+i]; //traces var id as text only, not the result id1
var id = this.evt.target.data.i;
var id = this.evt.target.data[i];
var id = this.evt.target.data+i;

不可能这样做? 还是我失踪了吗?

最佳回答

在对你试图做些什么表示非常怀疑的情况下,我认为这是你尝试的:

// ...
private var loader:URLLoader;

public function foo ( someUrl:String ):void
{
    loader = new URLLoader();
    loader.addEventListener( Event.COMPLETE, onComplete );
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.load( new URLRequest( someUrl ) );
}

private function onComplete ( event:Event )
{
    var total:int = int( event.target.data.total );

    for ( var i:int = 1; i <= total; i++ )
    {
        trace( event.target.data[  id  + i ] );
        trace( event.target.data[  content  + i ] );
    }
}
问题回答

这是我的法典:

var request:URLRequest = new URLRequest("http://localhost:8888/lifestyle/get.php?type=blog");
request.method = URLRequestMethod.GET;

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, completeHandler);
loader.load(request);

function completeHandler(evt:Event) {

  //var blancData = evt.target.data.blancData;
  var total = evt.target.data.total;
  var id = evt.target.data.id;
  var content = evt.target.data.content;

  for (var i:Number=1; i<=total;i++){ 
    var id = evt.target.data.id;
    var content = evt.target.data.content;
    trace ( id uit DB:   + id);
    trace ( content uit DB:   + content);
    }

 // trace ( totaal rijen in DB:   + total);
  //trace ( id uit DB:   + id);
  //trace ( content uit DB:   + content);
}

工作!

@Poke thank you for your answer!! You ve pointed me to the right direction!

var content = evt.target.data[ content  + i];

我现在要lap,因为我以前没有看到这一点:





相关问题
Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签