To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 06-12-2006, 11:06 PM   #1
whispers
Moderator
 
whispers's Avatar
 
Join Date: Mar 2001
Location: CFA2h (respect the HEX)
Posts: 11,647
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);
	}
}
whispers is offline   Reply With Quote
Old 06-13-2006, 02:18 AM   #2
Dricciotti
frankenmoderator
 
Dricciotti's Avatar
 
Join Date: Aug 2002
Location: Indiana/Maryland
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?
__________________
thumbs up!
On Giant Shoulders
Dricciotti is offline   Reply With Quote
Old 06-13-2006, 02:39 AM   #3
whispers
Moderator
 
whispers's Avatar
 
Join Date: Mar 2001
Location: CFA2h (respect the HEX)
Posts: 11,647
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...
whispers is offline   Reply With Quote
Old 06-13-2006, 02:43 AM   #4
whispers
Moderator
 
whispers's Avatar
 
Join Date: Mar 2001
Location: CFA2h (respect the HEX)
Posts: 11,647
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..
whispers is offline   Reply With Quote
Old 06-13-2006, 04:43 PM   #5
whispers
Moderator
 
whispers's Avatar
 
Join Date: Mar 2001
Location: CFA2h (respect the HEX)
Posts: 11,647
Dricciotti-

I loose ya? Any ideas?
whispers is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:48 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.