A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: call function from another scope (delegate)

Hybrid View

  1. #1
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755

    call function from another scope (delegate)

    I am having trouble trying to call this whole routine (again) once a 'save button' is clicked (basically want to re-populate to reflect changes)

    this already gets called ONCE (intitally) on the movie/project Load...

    1.) I have tried to wrap the whole thing (routine) in a function, but then it stops working as it should (doesnt populate correctly, everything becomes 'undefined')

    2.) I have tried pathing to the specific functions from my save button (located on _root)...but no go...(failed load)

    here is the code (all of it) I need to 're-call' and run, when the save button is clicked.

    thanks for anything I am missing:

    Code:
    import mx.utils.Delegate;
    //
    var rootNode:XMLNode;
    var productsNode:Array;
    var totalProducts:Number;
    var myProducts_xml = new XML();
    //
    myProducts_xml.ignoreWhite = true;
    myProducts_xml.onLoad = Delegate.create(this, getTotalProducts);
    myProducts_xml.load("prodData/products.xml"); //local version
    //myProducts_xml.load("prodData/products.xml?ran="+random(999999)); //web version (cache killer)
    
    //
    function getTotalProducts(success):Void {
    	if (success == true) {
    		rootNode = myProducts_xml.firstChild;
    		productsNode = rootNode.childNodes;
    		totalProducts = rootNode.childNodes.length;
    		createProducts();
    		this.onEnterFrame = Delegate.create(this, function() {
    			populateAll();
    			delete this.onEnterFrame;
    			}//end Function	
    		); //end Delegate	
    	}else {
    		trace("INIITIAL Load Failed");
    	}
    }
    
    //
    function createProducts():Void {
        //Define how many columns
        var columns:Number = 1;
        //Define the item vSpacing;
        var vSpacing:Number = 10;
        //Define the item hSpacing;
        var hSpacing:Number = 0;
        for (i=0; i<totalProducts; i++) {
            var attachProduct:MovieClip = attachMovie("productEntry", "product"+i, i);
    		attachProduct._x += 10;
    		attachProduct._y += 0;		
            attachProduct._y += i * 45;
            //attachProduct._y = Math.floor(i / columns) * hSpacing; //only used with multiple columns
    		//attachProduct._x = Math.floor(i % columns) * vSpacing; //only used with multiple columns
        }
    }
    
    //populate
    function populateAll():Void {
    	for (i = 0; i < totalProducts; i++) {
    		var totalQuantity:Number =productsNode[i].childNodes[7].childNodes.length;
    		
    		//random data
    		var obj = this["product" + i];
    		    obj.prodNum = i; //declaring what product (node) this is
    		
    		//currentImage
    		var prodImage:String = productsNode[i].childNodes[0].firstChild.nodeValue;
    		var obj = this["product" + i];
    		    obj.currentImage = prodImage;
    		    //obj.currentImage = obj.currentImage.toUpperCase();
    			obj.currentImage = obj.currentImage.toLowerCase();
    		
    		//name
    		var prodName:String = productsNode[i].childNodes[1].firstChild.nodeValue;
    		var obj = this["product" + i];
    			obj.name_txt.text = prodName +i;
    			obj.name_txt.text = obj.name_txt.text.toUpperCase();
    			
    		//price
    		var prodPrice:Number = productsNode[i].childNodes[2].firstChild.nodeValue;
    		var obj = this["product" + i];
    			obj.selectedPrice = ["$"+prodPrice];
    			obj.price_txt.text = obj.selectedPrice;
    			//trace("PRICE :"+obj.selectedPrice);
    			
    		//description
    		var prodDesc:String = productsNode[i].childNodes[5].firstChild.nodeValue;
    		var obj = this["product" + i];
    			obj.descriptionVar = prodDesc;
    			obj.descriptionVar = obj.descriptionVar.toUpperCase();
    			//obj.descriptionVar = obj.descriptionVar.toLowerCase();
    			
    		//colors
    		var colorLength:Number =productsNode[i].childNodes[4].childNodes.length;
    		trace("Total Colors: "+colorLength);
    		for (z = 0; z < colorLength; z++) {
    			var totalColors:Array =productsNode[i].childNodes[4].childNodes[z].firstChild.nodeValue;
    			var obj = this["product" + i];
    				obj.colorChoices.push(totalColors);
    		}
    		//sizes
    		var sizeLength:Number =productsNode[i].childNodes[3].childNodes.length;
    		trace("Total Sizes: "+sizeLength);
    		for (y = 0; y < sizeLength; y++) {
    			var totalSizes:Array =productsNode[i].childNodes[3].childNodes[y].firstChild.nodeValue;
    			var obj = this["product" + i];
    				obj.sizeChoices.push(totalSizes);
    		}
    		trace("Color Array: "+obj.colorChoices);
    		trace("Size Array: "+obj.sizeChoices);
    		trace(newline);
    	}
    }

  2. #2
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    So you want to run this part of the top of the code again?
    Code:
    import mx.utils.Delegate;
    //
    var rootNode:XMLNode;
    var productsNode:Array;
    var totalProducts:Number;
    var myProducts_xml = new XML();
    //
    myProducts_xml.ignoreWhite = true;
    myProducts_xml.onLoad = Delegate.create(this, getTotalProducts);
    myProducts_xml.load("prodData/products.xml"); //local version
    //myProducts_xml.load("prodData/products.xml?ran="+random(999999)); //web version (cache killer)
    
    //
    Does throwing just that above stuff into a function give you those 'undefined' problems you were talking about?

  3. #3
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    HOORAY!...someone is here...I was just about to call it quits..

    I try right now...

    now it does even initially run/ececute..

    Code:
    function intialRead() {
    import mx.utils.Delegate;
    //
    var rootNode:XMLNode;
    var productsNode:Array;
    var totalProducts:Number;
    var myProducts_xml = new XML();
    //
    myProducts_xml.ignoreWhite = true;
    myProducts_xml.onLoad = Delegate.create(this, getTotalProducts);
    myProducts_xml.load("http://www.dmstudios.net/flashCart_final/prodData/products.xml"); //local version
    //myProducts_xml.load("prodData/products.xml?ran="+random(999999)); //web version (cache killer)
    }
    
    //call above initialRead(); function
    initialRead();
    //
    then the rest as usual..there has to be a way to get this to execute again....

    I'd hate to have to resort to a COMPLETE page refresh...

    this darn Delegate.create function has been the BANE of my exsistence since I found out about it!! LOL

    I wouldnt mind sending yout he WHOLE project (if need be)...but its pretty big...and Im sure noone codes the same..and its always a task to debug others work... but I really dont know how to excute that code again.

    it reside in a several time over nexted clip (frame 1)

    that executes when the movie loads....

    what I need to do is run that again from a button on _root. and I have seriously tried a million way sof pathing..recalling the Delegate funtion over, from different scopes...etc..etc..

    Im dead in the water...

  4. #4
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    UPDATE:

    ok..I had a typo... in the function name (corrected, should be initialRead() ..)

    anyways...so it is NOW getting hung up on the other Delegates I believe...


    as this trace fires:
    Code:
    function getTotalProducts(success):Void {
    	trace("getTotalProducts Called");
    and thats the last I see...

    no products ..nothing populates still..

  5. #5

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