Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts

    movie clip doesn't talk to UILoader

    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:
    Code:
    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:
    Code:
    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
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Try:
    Code:
    function showPhoto(event:MouseEvent):void {
    	viewer_mc.load(new URLRequest(event.target.name));
    
    }

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts
    Doesn't work. I've tried many permutations.
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts
    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?
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Attach your fla file.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts
    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.
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    This gets rid of the error but then a new one arises
    Code:
    function showPhoto(event:MouseEvent):void {
    	this.viewer_mc.load(new URLRequest(event.target.name));
    }
    Code:
    TypeError: Error #1010: A term is undefined and has no properties.
    	at thumbstrip/showPhoto()
    Unfortunately I'm too tired to try to debug it.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #8
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts
    Is there a different way to access the UILoader?
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #10
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts
    No answers. Still doesn't work. Heavy sigh.
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx

  • #11
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #12
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts
    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.
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx

  • #13
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts
    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.

    Code:
    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.
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •