Question

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 property.

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

Was it helpful?

Solution

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]

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top