The following examples show how you can dynamically load an image in ActionScript 2.0 and ActionScript 3.0 using the MovieClip class and Loader class.
Full code after the jump.
The following example shows how you can dynamically load an image using the createEmptyMovieClip() and loadMovie() methods in ActionScript 2.0:
// ActionScript 2.0 var url:String = "http://www.helpexamples.com/flash/images/image2.jpg"; var movieClip:MovieClip = createEmptyMovieClip("movieClip", 0); movieClip.loadMovie(url);
The following example shows how you can dynamically load an image using the Loader class in ActionScript 3.0:
// ActionScript 3.0 var url:String = "http://www.helpexamples.com/flash/images/image2.jpg"; var urlRequest:URLRequest = new URLRequest(url); var loader:Loader = new Loader(); loader.load(urlRequest); addChild(loader);
13 Responses to Dynamically loading an image in ActionScript 2.0 and ActionScript 3.0
Leave a Reply Cancel reply
Recent Posts
- Getting started with the TLFTextField class in ActionScript 3.0 and Flash CS5
- Adding tick marks to a Slider control in Flash using ActionScript 3.0
- Creating a vertical Slider control in Flash using ActionScript 3.0
- Creating a custom context menu item in Flash using ActionScript 3.0
- Rotating a Sprite object around its x-axis in Flash using ActionScript 3.0 and Flash Player 10
- Detecting when the user changes the color in a ColorPicker control in Flash using ActionScript 3.0
- Getting the currently selected color as a hexadecimal value on a ColorPicker control in Flash using ActionScript 3.0
- Toggling the text field on the ColorPicker control in Flash using ActionScript 3.0
- Creating a vertical Slider control in Flash using ActionScript 3.0
- Setting the number of columns on a ColorPicker control in Flash using ActionScript 3.0
Categories
- Bitmap (1)
- Components (72)
- Button (19)
- CheckBox (2)
- ColorPicker (6)
- ComboBox (1)
- DataGrid (8)
- FLVPlayback (7)
- Label (9)
- ProgressBar (2)
- Slider (3)
- TextArea (1)
- TextInput (7)
- UILoader (7)
- ContextMenu (1)
- Embed (4)
- ExternalInterface (2)
- Flex (7)
- Font (2)
- General (5)
- Graphics (2)
- JSFL (14)
- Loader (3)
- LoadVars (3)
- Microphone (1)
- migration (12)
- MovieClip (1)
- MovieClipLoader (1)
- Sound (2)
- TextField (1)
- TLFTextField (1)
- TransitionManager (1)
- Tween (1)
- Uncategorized (1)
- URLLoader (4)
- URLVariables (1)
- Video (1)
- XML (2)
Advertising
" RT @OReillyMedia: #Ebook Deal/Day: Learning JavaScript Design Patterns -
$11.99
(Save 50%)
http://t.co/ilcmSDv6 " — pdehaan


Hi can you send me the FLA file for this
hey,
this tuturoal is really helpful thank you.
One question – how do you add more than one image using this AS?
I copyed the code and pasted below but its not working for some reason?
thanks
Tremain
thanks
Thank you for the easy guide ^_^
it also seems that you can change the image whenever you want by redoing the
movieClip.loadMovie(url);
line and giving a different url without having to redo the whole lot XD
(probibly obvious but thought i would say it anyway)
Useless example!
Running the Example code for ActionScript 3.0 results in an error:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Loader@1946e6a1 to mx.core.IUIComponent.
You can’t display the content of a Loader that easy.
Mark,
This example was for Flash CS3/CS4/ActionScript 3.0, not for a Flex project.
Peter
Great work. Simple. There is one doubt though. I get an error when I execute the code ..
Error opening URL ‘http://www.helpexamples.com/flash/images/image2.jpg’
Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
I replaced the URL with a file on my system, then it works fine. I tried replacing your link with another link from my website, but it gave the same error. What might be the reason? Im suspecting a security sandbox issue, sometimes links dont work in Flash due to the network settings here. Or is it something to do with the code?
Regards and Thanks,
Roshan
This way is a little bit faster…
Everytime I try to use this script I get the following error:
Error opening URL '%SITE PATH%'Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
I’ve tried with many different site paths (all with correct URLs I even tried with the two in this tutorial!) but nothing seems to work :(
please help!
- Alex
Found out the error!!!
My firewall was blocking the request!
thanks man
How would I get this to work where you can click buttons to load these various images, one at a time?
HI
I made one swf file in which image load on mouse over
but every time it loads image when I mouse over it and take time
Can someone tell me how to avoid this everytime loading
I need a as by which once image is loaded it can be used any time and no need to load it again and again