...

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



marilynn.fowler
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");
addChild(imageLoader);
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 {
setDirection(-scrollAmt);
}

function scrollRight(event:MouseEvent):void {
setDirection(scrollAmt);
}

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

gnomeontherun
04-23-2008, 10:13 PM
Try:

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

}

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

marilynn.fowler
04-24-2008, 12:37 AM
I've tried many permutations:
root.viewer_mc
_root.viewer_mc
this.parent.viewer_mc
this.viewer_mc
stage.viewer_mc
viewer_mc.Avatar_component
viewer_mc.UILoader

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?

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

marilynn.fowler
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.

_Aerospace_Eng_
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.

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

_Aerospace_Eng_
04-24-2008, 10:28 PM
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/fl/containers/UILoader.html#load()

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

_Aerospace_Eng_
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?

marilynn.fowler
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.

marilynn.fowler
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum