Actionscript3.0 - Images do not appear in UILoader component

Here is how my project looks:
I have three layers:

Layer 1.… Here is movieclip (instance name: :“clip” ) contains seven buttons (inst. name “btn1”…".btn 3"…till …".btn7")
Layer2…Here is UILoader component inserted on stage (instance name " ui" )
Layer3…Here is in Frame1 …Actionscript

Problem is, when click on any button, no image from external file appears and ERROR shows up: Access of undefined property btn1, btn2,…btn7 ,should be script placed in layer3 or somewhere else? Will you help me?

Actionscript in Layer 3:

/**buttons
/

btn1.addEventListener(MouseEvent.CLICK, showImg1);
btn2.addEventListener(MouseEvent.CLICK, showImg2);
.
.
.
btn7.addEventListener(MouseEvent.CLICK, showImg7);

**/funkctions
/

function showImg1 (e:MouseEvent):void{
ui.source = “…/Images/img1.jpg”;
}
function showImg2 (e:MouseEvent):void{
ui.source = “…/Images/img2.jpg”;
}
.
.
.
function showImg7 (e:MouseEvent):void{
ui.source = “…/Images/img7.jpg”;
}

if your buttons are in clip, then you need to reference them in your actionscript as clip.btn1, clip.btn2, etc. Otherwise it thinks you’re looking for the buttons in the main timeline where they don’t exist, hence the error.

Oh thanks, I will try that.

My second question:
How to set any image that appearrs in UILoader component window after first start up UILoader. At first start of UILoader component window is empty. After clicking any buttons appears image from external file. Is it possible load the image at first start of UILoader and then change images from external file by clicking the buttons? Thank you for advice

yeah just set the source right away

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/containers/UILoader.html#source