View Full Version : movie clip doesn't talk to UILoader

04-23-2008, 09:49 PM
I have a movie clip containing thumbnails dynamically loaded from an XML file. I have a UILoader named viewer_mc on the main timeline. I can't make the movie clip clicks load the UILoader. Everything works but the showPhoto function. I get the following error message:

1120: Access of undefined property _root.

Here's the code on my movieclip:

var imageLoader:Loader;
var xml:XML;
var xmlList:XMLList;

var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("data/images.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(event:Event):void {
xml = XML(event.target.data);
xmlList = xml.children();

for(var i:int = 0; i < xmlList.length(); i++) {
imageLoader = new Loader();
imageLoader.load(new URLRequest(xmlList[i].attribute("thumb")));
imageLoader.x = (i * 61);
imageLoader.y = 0;
imageLoader.name = xmlList[i].attribute("source");
imageLoader.addEventListener(MouseEvent.CLICK, showPhoto);

function showPhoto(event:MouseEvent):void {
_root.viewer_mc.load(new URLRequest(event.target.name));


Here's my code on the mainstage:

var minScroll:Number = thumbs_mc.x;
var maxScroll:Number = minScroll + thumbs_mc.x - mask_mc.width;
var targetScroll:Number = thumbs_mc.x;
var scrollAmt:Number = 15;
var scrollDirection:Number = 0;
var easing:Number = 4;

function scrollLeft(event:MouseEvent):void {

function scrollRight(event:MouseEvent):void {

function setDirection(dir:Number):void {
//thumbs_mc.x += dir;
scrollDirection = dir;
stage.addEventListener(Event.ENTER_FRAME, scrollThumbs);
stage.addEventListener(MouseEvent.MOUSE_UP, stopScrolling);

function scrollThumbs(event:Event):void {
targetScroll += scrollDirection;
thumbs_mc.x = targetScroll;
if you don't like easing, comment out the next line instead
thumbs_mc.x -=(thumbs_mc.x - targetScroll) / easing;
if (thumbs_mc.x > minScroll) {
thumbs_mc.x = minScroll;
targetScroll = minScroll;
else if(thumbs_mc.x < maxScroll) {
thumbs_mc.x = maxScroll;
targetScroll = maxScroll;

function stopScrolling(event:MouseEvent):void {
scrollDirection = 0;

left_btn.addEventListener(MouseEvent.MOUSE_DOWN, scrollLeft);
right_btn.addEventListener(MouseEvent.MOUSE_DOWN, scrollRight);

My UILoader is named viewer_mc
My movie clip is named thumbs_mc

What am I doing wrong

04-23-2008, 10:13 PM

function showPhoto(event:MouseEvent):void {
viewer_mc.load(new URLRequest(event.target.name));


04-23-2008, 10:23 PM
Doesn't work. I've tried many permutations.

04-24-2008, 12:37 AM
I've tried many permutations:

I still get the "1120: Access to undefined property" error message. The offending line is definitly viewer_mc.load(new URLRequest(event.target.name));

When I trace event.target.name I get the expected results, but for some reason it just doesn't talk to the UILoader component when it's inside of a movie clip. why? Why? WHY?

04-24-2008, 02:39 AM
Attach your fla file.

04-24-2008, 06:16 AM
I zipped up the FLA, XML, photos, and thumbs: http://www.vicesbyproxy.com/staging/Archive.zip. I extrapolated the code from a tutorial on Lynda.com. It all works until I put the thumb loader into a movie clip. Then I get the error message.

04-24-2008, 06:49 AM
This gets rid of the error but then a new one arises

function showPhoto(event:MouseEvent):void {
this.viewer_mc.load(new URLRequest(event.target.name));

TypeError: Error #1010: A term is undefined and has no properties.
at thumbstrip/showPhoto()
Unfortunately I'm too tired to try to debug it.

04-24-2008, 10:13 PM
Is there a different way to access the UILoader?

04-24-2008, 10:28 PM

04-26-2008, 12:32 AM
No answers. Still doesn't work. Heavy sigh.

04-26-2008, 07:45 AM
You seem to be mixing up AS2 with AS3. The documentation I linked to shows how to properly communicate with the uiloader. Did you read it?

04-29-2008, 02:56 AM
I did read it. I saw that I could also use "source = " but I still get an error message and blinking screen. I can't seem to talk to my UILoader from a movie clip.

FYI, I don't have any experience with actionscript 2. Any code I've used is based on Lynda.com actionscript 3 tutorials in the last three weeks. I'm trying to teach myself coding, so things that may seem really obvious to you will go right over my head.

04-29-2008, 09:35 AM
Well, I found the answer at http://board.flashkit.com/board/showthread.php?t=762934. Once I realized that putting a simple button inside of a movie clip produced the same problem I could expand my search. I NEVER would have figured this out.

function showPhoto(event:MouseEvent):void {
(root as MovieClip).photoGallery.source = event.target.name;

(Root as MovieClip) !? WTF? Is that even legal? Whatever. It works. On to the next unfathomable problem.