开发者

Parsing a path in Actionscript 3?

I'm using a URLLoader to load a photo and I want to be able to display the filename of the photo based on the URLLoader's loaderInfo.url开发者_JS百科 property.

Given a loader named photoLoader, what the string called fileName be?


I would take the .url property and split it into an array using the / as the delimiter. Then just grab the last item in that array to get the filename.

Code:

var pathArray:Array = photoLoader.url.split('/')

var FileName:String = pathArray[pathArray.length()-1]


with

s:String = "http:/somedomain/someurl/somefilename";

You could do

fileName = s.split('/').pop()

to return the top of the array from splitting the url at '/'


var pathArray:Array = photoLoader.url.split('/')

var FileName:String = pathArray[pathArray.length-1]

Please note that the keyword "length" is not followed by parenthesis. For arrays, it is not supposed to be a function, it is a property. On the other hand, XML lists can use the length() function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜