dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] Gallery problem

  1. #1
    Senior Member
    Join Date
    Jan 2006
    Location
    Mount Joy, Pa
    Posts
    117

    resolved [RESOLVED] Gallery problem

    OK I have problem I need this gallery to have the scrolling thumbs at the bottom of the loader( moving x instead of y) instead of having it on the right side.

    TypeError: Error #1006: value is not a function.
    at gallery_fla::MainTimeline/thumbLoaded()

    Code:
    //this is the loader that will load our XML document
    var xmlLoader:URLLoader = new URLLoader();
    //and this is our XML object -- it will contain the loaded XML data
    var xmlData:XML = new XML;
    
    //this function is called to handle all the XML loading duties -- it receives the XML's location
    //as a string from a call to loadXml(...) below
    function loadXml(xmlFile:String):void {
    	//we add an event listener to check when the XML has finished loading
    	//once it has, we fire the xmlLoaded function
    	xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
    	//we also add an error-catching listener, which will tell us if there's a problem loading the XML
    	xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, xmlLoadFail);
    	//lastly, we load the XML by telling our URLLoader (above) to load the XML file
    	xmlLoader.load(new URLRequest(xmlFile));
    }
    //load the XML file
    loadXml("slideshow.xml");
    
    //this function is fired if there is an error loading the XML file
    function xmlLoadFail(event:IOErrorEvent):void {
    	trace("There's been an error loading the XML.  Try back in a moment.");
    }
    
    //if the data loads correctly, this function is called
    function xmlLoaded(e:Event):void {
    	//we define our xmlData object (from above) as the data of e.target, which in this case is xmlLoader
    	xmlData = XML(e.target.data);
    	loadThumbs();//call the thumbs loading function
    }
    
    
    //-------------------LOADING IMAGES------------------\\
    var padding:Number = 2; // this number is how much vertical space you want between thumbs
    var p:int = 0;//increment value
    var child:MovieClip;//var for empty movieClip that hold our thumbs
    //generic empty loader object
    var loader:Loader;
    //and a loader for our thumbnails
    var thumbLoader:Loader;
    //this function gets called if the XML loads without any problems
    function loadThumbs():void {
    	//we create a new instance of thumbLoader each time this is called
    	thumbLoader = new Loader();
    	//we add an event listener to its contentLoaderInfo (which contains loading data)
    	//this listener fires when the loading has completed (INIT = "initialized," or fully loaded & accessible)
    	thumbLoader.contentLoaderInfo.addEventListener(Event.INIT, thumbLoaded);
    	//and, last, we tell the Loader object to load the thumbnail as per our XML's <thumbnail> tag
    	thumbLoader.load(new URLRequest(String(xmlData.pic.thumb[p])));//access the thumbnails
    	
    	thumbLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void{ 
            trace("There's been an error loading a thumbnail: " + e.text); 
        }); 
    }
    
    //this function is fired once loading of a thumbnail has completed
    function thumbLoaded(e:Event):void {
    	//we create a new MovieClip
    	child = new MovieClip();
    	//add the content of our loader to the movie clip (so the movie clip is now the thumbnail)
    	child.addChild(thumbLoader.content);
    	//add an event listener to the movie clip which fires when it is clicked -- it loads the full-size image
    	child.addEventListener(MouseEvent.CLICK, loadBigImage);
    	//we tell the movie clip to behave as a button, which makes the mouse use the "hand cursor" when it is hovered over
    	child.buttonMode = true;
    	//here we set a variable INSIDE our new movie clip, which contains the URL of its full-size version
    	//we'll use this when loading the full-size image
    	child.largeimg = xmlData.pic.largeimg[p];
    	//once finished, add the movie clip to thumbnails_mc (which contains all the thumbs) so we can see it
    	thumbnails_mc.addChild(child);
    	/*And now we position it. Since it's a vertical scroller, we use the y property of the MovieClip.
    	We determine this new location by figuring out the height of this thumbnail (since they're all the same height),
    	adding a padding value to it (to space them a little), and multiplying that by p, which is the number corresponding
    	to the current section of XML we're working on.*/
    	child.x = (e.target.content.width+padding)*p;//set the x pos of the thumb to the changex var
    	//now we just check if p+1 is greater than the length of xmlData.pic (the individual pic entries in the XML)
    	//if it is not greater, we know we can call the loadThumbs function again, because there is at least one more thumb to load
    	if (++p<xmlData.pic.width()) {
    		loadThumbs();//create loop
    	}
    }
    //this is the function called by clicking a thumb
    //it simply tells myLoader (the UILoader Component on the Stage) to load its corresponding large image
    //the path to this large image is determined by the largeimg variable which we stored in each thumbnail above
    function loadBigImage(e:MouseEvent):void {
    	myLoader.load(new URLRequest(e.target.largeimg));
    }
    
    //------------------SCROLLING--------------------------\\
    //this adds a listener to thumbnails_mc, which will be used for scrolling
    thumbnails_mc.addEventListener(Event.ENTER_FRAME, scrollMe);
    //and this variable will hold the y position of the mouse -- it will also be used to scroll
    var lastMouse:Number = 0;
    
    //this is the scrolling function
    function scrollMe(e:Event):void {
    	//first we check to see if the mouse is near the pictures
    	//the math I've done basically just makes the "hot area" include all the space to the right
    	//of where the thumbnails begin -- since they're right on the edge, that is their whole area
    	if (mouseX>thumbnails_mc.X) {
    		//this variable stores the mouse's position once per frame
    		//we're storing this in an outside variable in order to produce smooth deceleration
    		//if the mouse moves outside of the "hot area" -- if we made this an INTERNAL variable,
    		//which would only update if the mouse was in the "hot area," the thumbnails would come to an immediate stop
    		//once rolled off of, which just isn't too attractive
    		lastMouse = mouseX;
    		//now, this is an easing formula
    		//it takes the difference between where the target is and where we want it to be
    		//then, it divides that number by a value which is called our "easing value"
    		//in this case, that value is the 5 at the end of each line of code (a larger number makes a slower transition)
    		//then we continually subtract this difference from our target's ACTUAL value
    		//this produces a nice smooth slide transition
    		thumbnails_mc.x -= (thumbnails_mc.x-padding-((thumbMask_mc.width-(thumbnails_mc.width+padding*2))/thumbMask_mc.width*lastMouse))/4;
    	} else {
    		//if the mouse is not in the "hot area," the transition continues to the last recorded value of "lastMouse,"
    		//which is the variable we were using above to store the mouse position
    		//since it is not updated in this case, it just slows to a stop instead of stopping immediately
    		thumbnails_mc.x -= (thumbnails_mc.x-padding-((thumbMask_mc.width-(thumbnails_mc.width+padding*2))/thumbMask_mc.width*lastMouse))/4;
    	}
    }
    OK I got it to load the first thumb but where is the other 33 ?
    Last edited by sunReedr; 03-26-2009 at 12:06 PM.

  2. #2
    Senior Member
    Join Date
    Jan 2006
    Location
    Mount Joy, Pa
    Posts
    117
    I tested in debug mode and it say :

    TypeError: Error #1006: value is not a function.
    at gallery_fla::MainTimeline/thumbLoaded()[gallery_fla.MainTimeline::frame1:78]

    here is line 78
    Code:
    if (++p<xmlData.pic.width()) {

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