help on adding (pushing) xml nodes into arrays
- Quickstrike
- Newbie


- Joined: Mar 16, 2005
- Posts: 7
- Status: Offline
I want to push and remove xml nodes into an array. This will be sort of like a collection basket, but I want to do this using xml and arrays.
When you click a button it will add an xml node (an image file) into a collection basket section. They you can either remove or view these images in your collections basket.
Could someone show me some examples and coding of how this is done? I'm a beginner at action scripting and need to see some functional coding to understand.
Thanks!
When you click a button it will add an xml node (an image file) into a collection basket section. They you can either remove or view these images in your collections basket.
Could someone show me some examples and coding of how this is done? I'm a beginner at action scripting and need to see some functional coding to understand.
Thanks!
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
March 16th, 2005, 9:59 am
- Abelius
- Proficient


- Joined: Sep 17, 2004
- Posts: 260
- Loc: Miami Beach, FL, USA
- Status: Offline
In order to add items to arrays I would go through the macromedia site and learn the "push", "splice" and "slice" of the trade...
After that you'll be ready to tackle XML, I don't suggest you do it before dealing well with arrays...
After that you'll be ready to tackle XML, I don't suggest you do it before dealing well with arrays...
Cordially,
Abel K - Miami Beach, FL, USA
http://www.worldkit.com
Abel K - Miami Beach, FL, USA
http://www.worldkit.com
- joebert
- Sledgehammer


- Joined: Feb 10, 2004
- Posts: 13458
- Loc: Florida
- Status: Offline
A basic example, Click on items to add them to the basket, click on items in the basket to remove them.
XML objects basically are arrays when you consider childNodes, placing chilldNodes into a variable gives you an easily accessable array of xml childNodes to deal with.
http://www.joebertvision.net/examples/f ... /index.swf
http://www.joebertvision.net/examples/f ... /index.fla (MX 6)
XML objects basically are arrays when you consider childNodes, placing chilldNodes into a variable gives you an easily accessable array of xml childNodes to deal with.
http://www.joebertvision.net/examples/f ... /index.swf
http://www.joebertvision.net/examples/f ... /index.fla (MX 6)
Code: [ Select ]
registerInventory = function(){
//register the products into a _global variable, this makes cloning the xml easier later on.
_global.registeredItems = this.firstChild.childNodes;
//show how many items are in the catalog
inventoryItems = registeredItems.length + " Items in inventory";
//delete the original XML object to free up memory
delete inventory;
//tell the display were ready to show the first item in our inventory
inventoryLoaded();
}
inventoryLoaded = function(){
//loop through the array of xml childNodes
for(var i=0; i<registeredItems.length; i++){
//attach a "product" mc for graphic representation
attachMovie("product", "product"+i, 100+i);
//set the label for this product
this["product"+i].label = unescape(registeredItems[i].attributes.name);
//link this mc to a basket childNode by product id
this["product"+i].id = unescape(registeredItems[i].attributes.id);
//position mc
this["product"+i]._x = 15;
this["product"+i]._y = 35+(i*25);
//attach addToBasket handler to mc
this["product"+i].onRelease = addToBasket;
}
}
addToBasket = function(){
//get a clone of the childNode associated with this MCs id
var item = getItem(this.id);
//attach the clone to the basket XML object
basket.appendChild(item);
//update graphic representation of basket
updateBasket();
}
removeFromBasket = function(){
//loop through childNodes of basket XML object untill a childNode with a product id matching the MCs id is found
for(var i=0; i<basket.childNodes.length; i++){
//if ids match remove the childNode from basket XML
if(this.id == unescape(basket.childNodes[i].attributes.id)){
basket.childNodes[i].removeNode();
//break loop
i = basket.childNodes.length;
}
}
//update graphic representation of basket
updateBasket();
}
function getItem(id){
var item;
//loop through registered items untill matching id is found
for(var i=0; i<registeredItems.length; i++){
if(unescape(registeredItems[i].attributes.id) == id){
//return a clone of the childNode, breaks the loop as well
return registeredItems[i].cloneNode(true);
}
}
}
updateBasket = function(){
//removes basketCase MC & all MCs attached to it, creates a fresh one
refreshBasketCase();
//loop through childNodes of basket XML
for(var i=0; i<basket.childNodes.length; i++){
//attach product MC for each childNode
basketCase.attachMovie("product", "product"+i, 200+i);
//set MC label/id for linkage
basketCase["product"+i].label = unescape(basket.childNodes[i].attributes.name);
basketCase["product"+i].id = unescape(basket.childNodes[i].attributes.id);
//position MC
basketCase["product"+i]._x = 0;
basketCase["product"+i]._y = i*25;
//set removeFromBasket handler
basketCase["product"+i].onRelease = removeFromBasket;
}
//show how many items are in the basket
basketItems = basket.childNodes.length + " Items in basket";
}
refreshBasketCase = function(){
//pretty self explainitory here
removeMovieClip(basketCase);
createEmptyMovieClip("basketCase", 99);
basketCase._x = 215;
basketCase._y = 35;
}
inventory = new XML();
inventory.ignoreWhite = true;
inventory.onLoad = registerInventory;
inventory.load("inventory.php");
createEmptyMovieClip("basketCase", 99);
basket = new XML();
basket.ignoreWhite = true;
//register the products into a _global variable, this makes cloning the xml easier later on.
_global.registeredItems = this.firstChild.childNodes;
//show how many items are in the catalog
inventoryItems = registeredItems.length + " Items in inventory";
//delete the original XML object to free up memory
delete inventory;
//tell the display were ready to show the first item in our inventory
inventoryLoaded();
}
inventoryLoaded = function(){
//loop through the array of xml childNodes
for(var i=0; i<registeredItems.length; i++){
//attach a "product" mc for graphic representation
attachMovie("product", "product"+i, 100+i);
//set the label for this product
this["product"+i].label = unescape(registeredItems[i].attributes.name);
//link this mc to a basket childNode by product id
this["product"+i].id = unescape(registeredItems[i].attributes.id);
//position mc
this["product"+i]._x = 15;
this["product"+i]._y = 35+(i*25);
//attach addToBasket handler to mc
this["product"+i].onRelease = addToBasket;
}
}
addToBasket = function(){
//get a clone of the childNode associated with this MCs id
var item = getItem(this.id);
//attach the clone to the basket XML object
basket.appendChild(item);
//update graphic representation of basket
updateBasket();
}
removeFromBasket = function(){
//loop through childNodes of basket XML object untill a childNode with a product id matching the MCs id is found
for(var i=0; i<basket.childNodes.length; i++){
//if ids match remove the childNode from basket XML
if(this.id == unescape(basket.childNodes[i].attributes.id)){
basket.childNodes[i].removeNode();
//break loop
i = basket.childNodes.length;
}
}
//update graphic representation of basket
updateBasket();
}
function getItem(id){
var item;
//loop through registered items untill matching id is found
for(var i=0; i<registeredItems.length; i++){
if(unescape(registeredItems[i].attributes.id) == id){
//return a clone of the childNode, breaks the loop as well
return registeredItems[i].cloneNode(true);
}
}
}
updateBasket = function(){
//removes basketCase MC & all MCs attached to it, creates a fresh one
refreshBasketCase();
//loop through childNodes of basket XML
for(var i=0; i<basket.childNodes.length; i++){
//attach product MC for each childNode
basketCase.attachMovie("product", "product"+i, 200+i);
//set MC label/id for linkage
basketCase["product"+i].label = unescape(basket.childNodes[i].attributes.name);
basketCase["product"+i].id = unescape(basket.childNodes[i].attributes.id);
//position MC
basketCase["product"+i]._x = 0;
basketCase["product"+i]._y = i*25;
//set removeFromBasket handler
basketCase["product"+i].onRelease = removeFromBasket;
}
//show how many items are in the basket
basketItems = basket.childNodes.length + " Items in basket";
}
refreshBasketCase = function(){
//pretty self explainitory here
removeMovieClip(basketCase);
createEmptyMovieClip("basketCase", 99);
basketCase._x = 215;
basketCase._y = 35;
}
inventory = new XML();
inventory.ignoreWhite = true;
inventory.onLoad = registerInventory;
inventory.load("inventory.php");
createEmptyMovieClip("basketCase", 99);
basket = new XML();
basket.ignoreWhite = true;
- registerInventory = function(){
- //register the products into a _global variable, this makes cloning the xml easier later on.
- _global.registeredItems = this.firstChild.childNodes;
- //show how many items are in the catalog
- inventoryItems = registeredItems.length + " Items in inventory";
- //delete the original XML object to free up memory
- delete inventory;
- //tell the display were ready to show the first item in our inventory
- inventoryLoaded();
- }
- inventoryLoaded = function(){
- //loop through the array of xml childNodes
- for(var i=0; i<registeredItems.length; i++){
- //attach a "product" mc for graphic representation
- attachMovie("product", "product"+i, 100+i);
- //set the label for this product
- this["product"+i].label = unescape(registeredItems[i].attributes.name);
- //link this mc to a basket childNode by product id
- this["product"+i].id = unescape(registeredItems[i].attributes.id);
- //position mc
- this["product"+i]._x = 15;
- this["product"+i]._y = 35+(i*25);
- //attach addToBasket handler to mc
- this["product"+i].onRelease = addToBasket;
- }
- }
- addToBasket = function(){
- //get a clone of the childNode associated with this MCs id
- var item = getItem(this.id);
- //attach the clone to the basket XML object
- basket.appendChild(item);
- //update graphic representation of basket
- updateBasket();
- }
- removeFromBasket = function(){
- //loop through childNodes of basket XML object untill a childNode with a product id matching the MCs id is found
- for(var i=0; i<basket.childNodes.length; i++){
- //if ids match remove the childNode from basket XML
- if(this.id == unescape(basket.childNodes[i].attributes.id)){
- basket.childNodes[i].removeNode();
- //break loop
- i = basket.childNodes.length;
- }
- }
- //update graphic representation of basket
- updateBasket();
- }
- function getItem(id){
- var item;
- //loop through registered items untill matching id is found
- for(var i=0; i<registeredItems.length; i++){
- if(unescape(registeredItems[i].attributes.id) == id){
- //return a clone of the childNode, breaks the loop as well
- return registeredItems[i].cloneNode(true);
- }
- }
- }
- updateBasket = function(){
- //removes basketCase MC & all MCs attached to it, creates a fresh one
- refreshBasketCase();
- //loop through childNodes of basket XML
- for(var i=0; i<basket.childNodes.length; i++){
- //attach product MC for each childNode
- basketCase.attachMovie("product", "product"+i, 200+i);
- //set MC label/id for linkage
- basketCase["product"+i].label = unescape(basket.childNodes[i].attributes.name);
- basketCase["product"+i].id = unescape(basket.childNodes[i].attributes.id);
- //position MC
- basketCase["product"+i]._x = 0;
- basketCase["product"+i]._y = i*25;
- //set removeFromBasket handler
- basketCase["product"+i].onRelease = removeFromBasket;
- }
- //show how many items are in the basket
- basketItems = basket.childNodes.length + " Items in basket";
- }
- refreshBasketCase = function(){
- //pretty self explainitory here
- removeMovieClip(basketCase);
- createEmptyMovieClip("basketCase", 99);
- basketCase._x = 215;
- basketCase._y = 35;
- }
- inventory = new XML();
- inventory.ignoreWhite = true;
- inventory.onLoad = registerInventory;
- inventory.load("inventory.php");
- createEmptyMovieClip("basketCase", 99);
- basket = new XML();
- basket.ignoreWhite = true;
Code: [ Select ]
<?xml version="1.0" encoding="iso-8859-1"?>
<inventory>
<product id="1" name="product+1" stock="966" price="9895">
<description> this is product ones description </description>
</product>
<product id="2" name="product+2" stock="926" price="91895">
<description> this is product twos description </description>
</product>
<product id="3" name="product+3" stock="266" price="12345">
<description> this is product threes description </description>
</product>
</inventory>
<inventory>
<product id="1" name="product+1" stock="966" price="9895">
<description> this is product ones description </description>
</product>
<product id="2" name="product+2" stock="926" price="91895">
<description> this is product twos description </description>
</product>
<product id="3" name="product+3" stock="266" price="12345">
<description> this is product threes description </description>
</product>
</inventory>
- <?xml version="1.0" encoding="iso-8859-1"?>
- <inventory>
- <product id="1" name="product+1" stock="966" price="9895">
- <description> this is product ones description </description>
- </product>
- <product id="2" name="product+2" stock="926" price="91895">
- <description> this is product twos description </description>
- </product>
- <product id="3" name="product+3" stock="266" price="12345">
- <description> this is product threes description </description>
- </product>
- </inventory>
Code: [ Select ]
<?php
require("includes/sql_config.php");
$pic_base = "images/inventory/";
$sql = "SELECT * FROM inventory";
$inventory = mysql_query($sql);
$inventory_xml = array(
'<?xml version="1.0" encoding="iso-8859-1"?>',
'<inventory picbase="'. urlencode($pic_base) . '">'
);
while($item = mysql_fetch_assoc($inventory)){
$inventory_xml[] = '<product id="' . urlencode($item['id']) . '" name="' . urlencode($item['name']) . '" stock="' . urlencode($item['stock']) . '" price="' . urlencode($item['price']) . '" pic="' . urlencode($item['pic']) . '"><description><![CDATA[ ' . $item['description'] . ' ]]></description></product>';
}
$inventory_xml[] = '</inventory>';
$inventory_xml = implode("", $inventory_xml);
header("Content-Type:text/xml");
echo $inventory_xml;
/*
<?xml version="1.0" encoding="iso-8859-1"?>
<inventory>
<product id="1" name="product+1" stock="966" price="9895">
<description> this is product ones description </description>
</product>
<product id="2" name="product+2" stock="926" price="91895">
<description> this is product twos description </description>
</product>
<product id="3" name="product+3" stock="266" price="12345">
<description> this is product threes description </description>
</product>
</inventory>
*/
?>
require("includes/sql_config.php");
$pic_base = "images/inventory/";
$sql = "SELECT * FROM inventory";
$inventory = mysql_query($sql);
$inventory_xml = array(
'<?xml version="1.0" encoding="iso-8859-1"?>',
'<inventory picbase="'. urlencode($pic_base) . '">'
);
while($item = mysql_fetch_assoc($inventory)){
$inventory_xml[] = '<product id="' . urlencode($item['id']) . '" name="' . urlencode($item['name']) . '" stock="' . urlencode($item['stock']) . '" price="' . urlencode($item['price']) . '" pic="' . urlencode($item['pic']) . '"><description><![CDATA[ ' . $item['description'] . ' ]]></description></product>';
}
$inventory_xml[] = '</inventory>';
$inventory_xml = implode("", $inventory_xml);
header("Content-Type:text/xml");
echo $inventory_xml;
/*
<?xml version="1.0" encoding="iso-8859-1"?>
<inventory>
<product id="1" name="product+1" stock="966" price="9895">
<description> this is product ones description </description>
</product>
<product id="2" name="product+2" stock="926" price="91895">
<description> this is product twos description </description>
</product>
<product id="3" name="product+3" stock="266" price="12345">
<description> this is product threes description </description>
</product>
</inventory>
*/
?>
- <?php
- require("includes/sql_config.php");
- $pic_base = "images/inventory/";
- $sql = "SELECT * FROM inventory";
- $inventory = mysql_query($sql);
- $inventory_xml = array(
- '<?xml version="1.0" encoding="iso-8859-1"?>',
- '<inventory picbase="'. urlencode($pic_base) . '">'
- );
- while($item = mysql_fetch_assoc($inventory)){
- $inventory_xml[] = '<product id="' . urlencode($item['id']) . '" name="' . urlencode($item['name']) . '" stock="' . urlencode($item['stock']) . '" price="' . urlencode($item['price']) . '" pic="' . urlencode($item['pic']) . '"><description><![CDATA[ ' . $item['description'] . ' ]]></description></product>';
- }
- $inventory_xml[] = '</inventory>';
- $inventory_xml = implode("", $inventory_xml);
- header("Content-Type:text/xml");
- echo $inventory_xml;
- /*
- <?xml version="1.0" encoding="iso-8859-1"?>
- <inventory>
- <product id="1" name="product+1" stock="966" price="9895">
- <description> this is product ones description </description>
- </product>
- <product id="2" name="product+2" stock="926" price="91895">
- <description> this is product twos description </description>
- </product>
- <product id="3" name="product+3" stock="266" price="12345">
- <description> this is product threes description </description>
- </product>
- </inventory>
- */
- ?>
- Quickstrike
- Newbie


- Joined: Mar 16, 2005
- Posts: 7
- Status: Offline
Thanks for the coding, joebert, it was helpful!
Right now I'm trying to learn how to apply shared objects, and try to make a checkout button that writes a .sol file so I can record what the user actually checks out on the client side.
Thoughts on this?
Basically I'm trying to set up a personal portfolio page and try to record what pieces the user in interested in.
Thanks!
Right now I'm trying to learn how to apply shared objects, and try to make a checkout button that writes a .sol file so I can record what the user actually checks out on the client side.
Thoughts on this?
Basically I'm trying to set up a personal portfolio page and try to record what pieces the user in interested in.
Thanks!
- joebert
- Sledgehammer


- Joined: Feb 10, 2004
- Posts: 13458
- Loc: Florida
- Status: Offline
Theese would allow you to store ids in a SOL, going on the code above.
Code: [ Select ]
//add param to basket function
addToBasket = function(id){
//get a clone of the childNode associated with this MCs id
var item = getItem(id ? id : this.id);
//attach the clone to the basket XML object
basket.appendChild(item);
//update graphic representation of basket
updateBasket();
}
//create shared object, attempt to find item ids & put them in the basket
cachedBasket = sharedobject.getLocal("basket");
cachedItems = cachedBasket.data.items.split("||");
for(var i=0; i<cachedItems.length; i++){
addToBasket(cachedItems[i]);
}
//cache basket
cacheBasket = function(){
basketItems = new Array();
for(var i=0; i<basket.childNodes.length; i++){
basketItems.push( unescape(basket.childNodes[i].attributes.id) );
}
cachedBasket.data.items = basketItems.join("||");
}
addToBasket = function(id){
//get a clone of the childNode associated with this MCs id
var item = getItem(id ? id : this.id);
//attach the clone to the basket XML object
basket.appendChild(item);
//update graphic representation of basket
updateBasket();
}
//create shared object, attempt to find item ids & put them in the basket
cachedBasket = sharedobject.getLocal("basket");
cachedItems = cachedBasket.data.items.split("||");
for(var i=0; i<cachedItems.length; i++){
addToBasket(cachedItems[i]);
}
//cache basket
cacheBasket = function(){
basketItems = new Array();
for(var i=0; i<basket.childNodes.length; i++){
basketItems.push( unescape(basket.childNodes[i].attributes.id) );
}
cachedBasket.data.items = basketItems.join("||");
}
- //add param to basket function
- addToBasket = function(id){
- //get a clone of the childNode associated with this MCs id
- var item = getItem(id ? id : this.id);
- //attach the clone to the basket XML object
- basket.appendChild(item);
- //update graphic representation of basket
- updateBasket();
- }
- //create shared object, attempt to find item ids & put them in the basket
- cachedBasket = sharedobject.getLocal("basket");
- cachedItems = cachedBasket.data.items.split("||");
- for(var i=0; i<cachedItems.length; i++){
- addToBasket(cachedItems[i]);
- }
- //cache basket
- cacheBasket = function(){
- basketItems = new Array();
- for(var i=0; i<basket.childNodes.length; i++){
- basketItems.push( unescape(basket.childNodes[i].attributes.id) );
- }
- cachedBasket.data.items = basketItems.join("||");
- }
Strong with this one, the sudo is.
- Quickstrike
- Newbie


- Joined: Mar 16, 2005
- Posts: 7
- Status: Offline
I added that code, but I don't see an external .sol file being made when I run the .fla. Is that supposed to happen?
If a button is added (that says checkout) and if this checkout button is clicked, can it store the users selections placed in the basket in an external .sol file? and could it store their e-mail address or names as well?
I'm a bit confused right now, and if you could show me how this could work, then that would be great.
-Thanks!
If a button is added (that says checkout) and if this checkout button is clicked, can it store the users selections placed in the basket in an external .sol file? and could it store their e-mail address or names as well?
I'm a bit confused right now, and if you could show me how this could work, then that would be great.
-Thanks!
- Quickstrike
- Newbie


- Joined: Mar 16, 2005
- Posts: 7
- Status: Offline
Could the inventory button that adds the item to the basket disapear and be unclickable so the user can only add it once. if the user removes the item from the basket section -- the item will go back to the inventory section, and thus, the user can re-add it to the basket again.
This would help me out greatly, thanks!
This would help me out greatly, thanks!
- joebert
- Sledgehammer


- Joined: Feb 10, 2004
- Posts: 13458
- Loc: Florida
- Status: Offline
SOL files are stored in the "Application Data" folder if you're using windows, this by default is a hidden folder.
SOLs from websites as well as programs like Fireworks that use swfs within the program are stored in diffeent folders within this folder.
For instance, C:\Documents and Settings\%USERNAME%\Application Data\Macromedia\Flash Player\#SharedObjects\ will take you to a folder full of folders that have names comprised of random letters & numbers. Going into theese folders will bring up folders with websites for names. (yes it gets really confusing...)
Opening an SOL in notepad or somthing similar will give you a basically unreadable file, Seppy has an SOL reader if you want to take a look at what's in theese SOLs.
After taking a look at a few of thoose from the big boys like Macromedia or Kirupaforum you'll notice you can store everything from var a=1; to entire swf structures in them.
Here's a few Macromedia.com specific pages on SOLs as well http://www.google.com/search?q=site:www ... art=0&sa=N
SOLs from websites as well as programs like Fireworks that use swfs within the program are stored in diffeent folders within this folder.
For instance, C:\Documents and Settings\%USERNAME%\Application Data\Macromedia\Flash Player\#SharedObjects\ will take you to a folder full of folders that have names comprised of random letters & numbers. Going into theese folders will bring up folders with websites for names. (yes it gets really confusing...)
Opening an SOL in notepad or somthing similar will give you a basically unreadable file, Seppy has an SOL reader if you want to take a look at what's in theese SOLs.
After taking a look at a few of thoose from the big boys like Macromedia or Kirupaforum you'll notice you can store everything from var a=1; to entire swf structures in them.
Here's a few Macromedia.com specific pages on SOLs as well http://www.google.com/search?q=site:www ... art=0&sa=N
- Quickstrike
- Newbie


- Joined: Mar 16, 2005
- Posts: 7
- Status: Offline
- Quickstrike
- Newbie


- Joined: Mar 16, 2005
- Posts: 7
- Status: Offline
Could the collected items be sent to a different section in the timeline? is that possible?
I have included a .fla file to show you what I'm trying to do because I don't think I'm doing a good job explaining it.
http://www.student.yorku.ca/~niccolo/collect.fla
http://www.student.yorku.ca/~niccolo/inventory.xml
Please look at my file and help me out as best as you can.
So basically in the .fla I want to have different sections that will contain an inventory item. When each inventory item is clicked on it will disapear and then be added to the collections section in the timeline.
(you'll have to look at the file to understand)
-Thanks in advance.
I have included a .fla file to show you what I'm trying to do because I don't think I'm doing a good job explaining it.
http://www.student.yorku.ca/~niccolo/collect.fla
http://www.student.yorku.ca/~niccolo/inventory.xml
Please look at my file and help me out as best as you can.
So basically in the .fla I want to have different sections that will contain an inventory item. When each inventory item is clicked on it will disapear and then be added to the collections section in the timeline.
(you'll have to look at the file to understand)
-Thanks in advance.
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 10 posts
- Users browsing this forum: No registered users and 37 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
