A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [F8] Undefined value problem

  1. #1
    Junior Member
    Join Date
    Mar 2003
    Posts
    21

    [F8] Undefined value problem

    Code:
    function launchLargePhotoViewer() {
    		for (i=0;i<_root.photosArray.length;i++) {
    			//var photoFile = _root.photoXML.childNodes[0].childNodes[i].attributes.filename;
    			_root.detail.photoSec.photosHolder["img"+i].onRelease=function():Void {
    				var photoFile = _root.photoXML.childNodes[0].childNodes[i].attributes.filename;
    				_root.detail.largeViewerHolder.removeMovieClip();
    				_root.detail.createEmptyMovieClip("largeViewerHolder", _root.detail.getNextHighestDepth());
    				_root.detail.largeViewerHolder.attachMovie("largeViewer", "largeViewer"+i, _root.detail.largeViewerHolder.getNextHighestDepth(), {_x: 251.1, _y:-27.9});
    				_root.detail.largeViewerHolder["largeViewer"+i].createEmptyMovieClip("img", _root.detail.largeViewerHolder["largeViewer"+i].getNextHighestDepth());
    				_root.detail.largeViewerHolder["largeViewer"+i].img.loadMovie("images/md_"+photoFile+".jpg", i);
    				_root.detail.largeViewerHolder["largeViewer"+i].img._x = _root.detail.largeViewerHolder["largeViewer"+i].img._x + (_root.detail.largeViewerHolder._width - _root.detail.largeViewerHolder["largeViewer"+i].img._width)*.3;
    				_root.detail.largeViewerHolder["largeViewer"+i].img._y = _root.detail.largeViewerHolder["largeViewer"+i].img._y + (_root.detail.largeViewerHolder._height - _root.detail.largeViewerHolder["largeViewer"+i].img._height)*.15;
    			}
    		}
    I have "var photoFile = _root.photoXML.childNodes[0].childNodes[i].attributes.filename;" stated twice. The first one is commented out. If I uncomment that, and comment the second one, the function allows a "filename" value from an XML file to be loaded, but not the appropriate "filename" dependent upon which object is released.

    If I keep the first declaration of the photoFile variable commented, and leave the second one uncommented, I receive an undefined value instead of the appropriate value to be pulled from the XML file.

    I hope I'm making sense. What can I do to have it so that the variable photoFile receives the correct value from the XML file?

    Additional note: As you can see there is an array called photosArray. I originally had the variable photoFile pull the desired value from the photosArray array, but it was not working and was also giving me the undefined error.
    Last edited by Tandaemonium; 05-16-2007 at 10:37 AM.

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe try something like this...

    The value of ' i ' needs to be stored, so that it can be accessed by the onRelease function.

    Code:
    function launchLargePhotoViewer() {
    	for (i = 0; i < _root.photosArray.length; i++) {
    		var pHolder = _root.detail.photoSec.photosHolder["img" + i];
    		pHolder.ID = i
    		pHolder.onRelease = function() {
    			var photoFile = _root.photoXML.childNodes[0].childNodes[this.ID].attributes.filename;
    			_root.detail.largeViewerHolder.removeMovieClip();
    			_root.detail.createEmptyMovieClip("largeViewerHolder", _root.detail.getNextHighestDepth());
    			_root.detail.largeViewerHolder.attachMovie("largeViewer", "largeViewer" + this.ID, _root.detail.largeViewerHolder.getNextHighestDepth(), {_x:251.1, _y:-27.9});
    			_root.detail.largeViewerHolder["largeViewer" + this.ID].createEmptyMovieClip("img", _root.detail.largeViewerHolder["largeViewer" + this.ID].getNextHighestDepth());
    			_root.detail.largeViewerHolder["largeViewer" + this.ID].img.loadMovie("images/md_" + photoFile + ".jpg", this.ID);
    			_root.detail.largeViewerHolder["largeViewer" + this.ID].img._x = _root.detail.largeViewerHolder["largeViewer" + this.ID].img._x + (_root.detail.largeViewerHolder._width - _root.detail.largeViewerHolder["largeViewer" + this.ID].img._width) * .3;
    			_root.detail.largeViewerHolder["largeViewer" + this.ID].img._y = _root.detail.largeViewerHolder["largeViewer" + this.ID].img._y + (_root.detail.largeViewerHolder._height - _root.detail.largeViewerHolder["largeViewer" + this.ID].img._height) * .15;
    		};
    	}

  3. #3
    Junior Member
    Join Date
    Mar 2003
    Posts
    21
    That was it! Thank you!

    More books should have that small tip in it. I think I've had that problem a bunch of times before.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center