Regular expression in Actionscript

How could I get the images from flickr? Let Flash download an image from a specific URL is easy. But what I needed in this project is:
Let flash browse to a certain website, look for images on that site and download them: Not possible. Because its not a browser. It can’t really “open up a webpage” But of course, there is always a solution
What I did instead:
Flash downloads the page the images are on and stores the html as pure text. Then, we can let it search inside the text.
So what I want is that it searches for for example, wherever it finds it it would start copying until it finds .jpg . So in regular expression that might be something like*.jpg

But regular expression are different wherever they occur. So I had a good look at Adobes examples but couldn’t figure out one thing: It would always take the last .jpg match in the line and not the first.

so a line

“> bla bla” would return exactly that. And the RegEx documentation at adobes did not really clarify things. So I asked.

And, i can’t say quite how or why but “inhan” did solve my problem:

Hi there, I am stuck with a string search

ActionScript Code:
var str:String = “this is better than what is better.”;
var pattern:RegExp = /this.*better/gi;
var results:Array = str.match(pattern);

I want to search in a string from word1 to word2 and place all the results in an Array. So this should be accomplished using match().

However the above code would return ” this is better than what is better”
while it should return “this is better”.
So the output takes the last match in the line, but I want it only to output till the first match in the line.
It is not taking more line into the search.
Does someone know what I am missing?

ActionScript Code:
var str:String = “this is better than what is better. this should be better.”;
var pattern:RegExp = /this.*?(better)/gi;
var results:Array = str.match(pattern);

for (var i:int = 0; i < results.length; i++) {
trace(i, ">>”, results[i]);

// 0 >> this is better
// 1 >> this should be better
Ali Inhan

So, thanks to Inhan, here is the finished Flickr load script

var imageloader = new Loader();
		var imaloadertwo = new Loader();
		imageloader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
		imaloadertwo.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);

		var randomimagenumber:Number = Math.floor(Math.random()*workingimages.length);
		var imagestring:String = workingimages[randomimagenumber];
		var newpattern:RegExp = /photo_container pc_t.*?(farm)/gi;
		imagestring = imagestring.replace(newpattern,"http://farm");

		var newpatterntwo:RegExp = /jpg.*?(alt)/gi;
		imagestring = imagestring.replace(newpatterntwo,"jpg");
		var fileRequest:URLRequest = new URLRequest(imagestring); = "image"+workingimages.length;
		imageloader.load(fileRequest); = "image"+workingimages.length;
Print Friendly

Leave a Reply

6 + = twelve