The following example shows how you can control whether content is auto-loaded in a Flash ActionScript 3.0 UILoader container by setting the Boolean autoLoad property. If the autoLoad property is set to true, the content is automatically loaded whenever the source property is set or the load() method is called. If the autoLoad property is false, the content will not be loaded until the load() method is explicitly called.
Full code after the jump.
// ActionScript 3.0 /* Requires * - UILoader control in Flash library * - Button control in Flash library */ import fl.containers.UILoader; import fl.controls.Button; var uiLoader:UILoader = new UILoader(); uiLoader.autoLoad = false; uiLoader.source = "http://helpexamples.com/flash/images/image1.jpg"; uiLoader.move(10, 10); addChild(uiLoader); var button:Button = new Button(); button.label = "Load image"; button.addEventListener(MouseEvent.CLICK, button_click); button.move(10, 120); addChild(button); function button_click(evt:MouseEvent):void { uiLoader.load(); }
3 Responses to Determining whether a UILoader component auto loads content in Flash using 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


Hoping you can help. I am an absolute beginner. My problems are threefold:
1. Although my UILoader (CS5) is set to load and scale content automatically (i.e., “loader.scaleContent = true;” “loader.autoLoad = true;”), there is a split second delay when opening the gallery page in which the loaded photo appears unscaled and then is properly scaled into the loader. On first click of the page it is readily apparent; on subsequent clicks it is a distinct “flash” of the image before being scaled.
2. I am not confident my scripting is correct, even though it seems to work. Background info: the page is scripted on its own AS layer (separate from the main ACTIONS layer that controls the entire website timeline). Originally it imported external jpg images fine, except for pixelation problems with a few that I could not smooth using tips from tutorials. I then imported my images and converted them to movieclips that are exported to action script, and rescripted the page. Here is the entire code, but note that I dragged the UILoader component and a tilelist component to the stage on a separate portion of the website timeline, using “thumbnails” as the instance name for the tilelist, and “loader” as the instance name for the UILoader.
//remove labels from thumbnails
thumbnails.labelField = null;
//add content to thumbnails
thumbnails.addItem({source:”evert”});
thumbnails.addItem({source:”austincup”});
thumbnails.addItem({source:”petty”});
thumbnails.addItem({source:”nettles”});
thumbnails.addItem({source:”connors”});
thumbnails.addItem({source:”guidry”});
thumbnails.addItem({source:”keithcig”});
thumbnails.addItem({source:”happy”});
thumbnails.addItem({source:”mick”});
thumbnails.addItem({source:”austinac”});
thumbnails.addItem({source:”who”});
thumbnails.addItem({source:”lasorda”});
thumbnails.addItem({source:”frampton”});
thumbnails.addItem({source:”eckersley”});
thumbnails.addItem({source:”fidrych”});
//set column and row values
thumbnails.columnWidth = 98;
thumbnails.rowHeight = 66;
thumbnails.columnCount = 3;
thumbnails.rowCount = 5;
//set styles
thumbnails.setRendererStyle(“imagePadding”, .75);
//scale content to fit loader and load on opening
loader.source = “evert”;
loader.autoLoad = true;
addChild(loader);
loader.scaleContent = true;
//select thumbnails for loader
thumbnails.addEventListener(Event.CHANGE, celebselect);
function celebselect(event:Event):void {
loader.source = thumbnails.selectedItem.source;
loader.autoLoad = true;
addChild(loader);
loader.scaleContent = true;
}
3. Another problem was the the loader didn’t unload. When I navigated away to another page the loaded photo showed over the new page. After extensive and frustrating searching, I created what seemed to be a fix except for the delay referred to and an output error. On the first frame, main Actions layer at each button function below the “gotoAndPlay(_);” command I added “loader.unload();”. This seems to work but for the delay in scaling described above and the following error (which usually appears for each button: “TypeError: Error #1009: Cannot access a property or method of a null object reference. at FAMESHOTStest_fla::MainTimeline/fl_ClickToGoToAndPlayFromFrame_78().”
Ok, that’s more than a mouthful and a lot to ask, but there is nothing out there I can comprehend or at least cut and paste.
Thanks, M
One obvious point to follow up. When initial importing external images, I used two variables to pull in the images from the external folder (one to ID the source and another to make the URLRequest – see below); when I couldn’t devise a variable to load the movieclips despite extensive searching, you can see from the code I used “addChild(loader);” and plainly ID’d the loader.source w/o a variable. When that worked I assumed I didn’t need any variables, but that’s my ignorance.
//scale content to fit loader and load on opening
var imgurl:String = “Portfolio/evertsm.jpg”;
var myrequest:URLRequest = new URLRequest(imgurl);
loader.scaleContent = true;
loader.load(myrequest);
//select thumbnails for loader
thumbnails.addEventListener(Event.CHANGE, photoselect);
function photoselect (event:Event):void{
var imgurl:String = thumbnails.selectedItem.source;
var myrequest:URLRequest = new URLRequest(imgurl);
loader.scaleContent = true;
loader.load(myrequest);
}
Hello can anyone give a hand to a noobie?? :P
I have an animation website portfolio like in lynda tuts, I try to follow each step n thet tut but when i applly a UIloader the swf animation blocks on rotation and needs several clicks to go into place if I remove it the animation goes well.
the code shows no errors I´m confused pls help!!!
// TWEEN
import fl.transitions.Tween;
import fl.transitions.easing.*;
//BACKGROUND PHOTOS
var randomNumber:Number = Math.ceil(Math.random() * 5);
trace(randomNumber);
bklogo.source = “Imagens_site/fundologo” + randomNumber + “.png”;
// LISTENER BUTTONS
function moveContent(theXPosition:Number, theYPosition:Number, theRotation:Number, theSection:String):void{
trace(“X: “+theXPosition);
trace(“Y: “+theYPosition);
trace(“Rotation: “+theRotation);
var myxTween:Tween = new Tween(conteudo_ma,”x”,Regular.easeOut,conteudo_ma.x,theXPosition,1,true);
var myyTween:Tween = new Tween(conteudo_ma,”y”,Regular.easeOut,conteudo_ma.y,theYPosition,1,true);
var myrotationTween:Tween = new Tween(conteudo_ma,”rotation”,Regular.easeOut,conteudo_ma.rotation,theRotation,1,true);
loadersec.source = theSection;
}
conteudo_ma.home_btn.addEventListener(MouseEvent.CLICK, homeClick);
function homeClick(MouseEvent):void
{
trace(“homeClick”);
moveContent(-600,-750,0,null);
}
conteudo_ma.bio_btn.addEventListener(MouseEvent.CLICK, bioClick);
function bioClick(MouseEvent):void
{
trace(“bioClick”);
moveContent(-285,1450,-90,”bio.swf”);
}
conteudo_ma.info_btn.addEventListener(MouseEvent.CLICK, infoClick);
function infoClick(MouseEvent):void
{
trace(“infoClick”);
moveContent(-915,-582,0,null);
}
conteudo_ma.port_btn.addEventListener(MouseEvent.CLICK, portClick);
function portClick(MouseEvent):void
{
trace(“portClick”);
moveContent(-1030,1438,-90,null);
}