Member Avatar for Moirae

Hello, I'm making a photo gallery using Flash, AS3 and I'm supposed to use URLRequest. Can someone please explain to me what is its purpose? My gallery works fine but I don't understand what this class id used for? I read some articles on Internet and it says

The URLRequest class captures all of the information in a single HTTP request.

I really don't understand what this means, can someone please try to explain?

I know the documentation isn't particularly clear even in the Adobe livedocs, but in it's simplest terms; As far as I understand it, an URLRequest object basically just holds a link, a http:// URL.

After creating an URLRequest, to use it you need to call something like the navigateToURL function, passing in the appropriate URLRequest.

For example. Imagine we have a movieclip or sprite in our movie which we want to use as a button. When the button is clicked, we want the user to be redirected to another website.
First up we'll create an URLRequest object to hold the URL:

var link:URLRequest = new URLRequest("http://www.mysite.com");

Next, add a click handler to our button/object:

// add the handler to the button object
myButton_mc.addEventListener(MouseEvent.CLICK, onClick);

// handler code
function onClick(event:MouseEvent):void 
{
	navigateToURL(link);
}

In the handler itself, you call navigateToURL passing our URLRequest (the variable 'link' in this example!)

One thing to bear in mind, if using a movieclip as a button you might want to set the buttonMode property to true.
e.g.

myButton_mc.buttonMode = true;

And that's about it for this example!

There are other uses of URLRequest. You can also pass URLRequest objects into functions like HTMLLoader.load(), URLLoader.load(), URLStream.load(), FileReference.upload(), FileReference.download(), and many others. Obviously which of these you use will depend on exactly what you're trying to do in your project.

Cheers for now,
Jas.

Member Avatar for Moirae

This is great, thanks a lot, you helped so much :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.