-
Mini shopping cart help
Hi,
I have the Flash and PHP Bible and am trying to get the miniShoppingCart to work, but am unable to do so.
The files are available here: chapter 12
http://www.wiley.com/WileyCDA/WileyT...-DOWNLOAD.html
There is an error in the source code of the fla file line 27 reads:
Code:
item.setStoreData(id, xmlItem.attribute('name'), xmlItem.attribute('desc'), xmlItem.attribute('thumbnail'));
but should be:
Code:
item.setStoreData(id, xmlItem.attribute('name'), xmlItem.attribute('desc'), xmlItem.attribute('thumbnail'),xmlItem.attribute('price'));
I manually set up a database with a table named flashStore_products and put in a sample record filling in the name, description and price columns.
I am trying to run it off a server and do get an error of 'XML parser failure: element is malformed'. Im not sure if this is because its unable to process the php or not, but the productsLoaded function seems to be throwing that error. Here is the code for that function:
Code:
function productsLoaded(e:Event):void
{
var urlLoader:URLLoader = URLLoader(e.target);
var xml:XML = new XML(urlLoader.data);
trace("XML: " + xml);
var id:uint = 0;
for each(var xmlItem in xml..product)
{
var item:StoreItem = new StoreItem();
item.y = 85 * id;
item.setStoreData(id, xmlItem.attribute('name'), xmlItem.attribute('desc'), xmlItem.attribute('thumbnail'),xmlItem.attribute('price'));
item.addToCartBtn.addEventListener(MouseEvent.CLICK, addItemHandler);
storeItems.addChild(item);
id++;
}
addChild(storeItems);
}
This is the relevant php code located in the flashCart.php file:
Code:
function getProducts()
{
global $link;
$result = mysql_query("SELECT * FROM flashStore_products WHERE active=1", $link);
$xml = "<products>\n";
while($row = mysql_fetch_array($result))
{
$xml .= "<product id=\"" . $row['id'] .
"\" name=\"" . $row['name'] .
"\" desc=\"" . $row['description'] .
"\" thumbnail=\"" . $row['thumbnail'] . "\" />\n";
}
$xml .= "</products>";
return $xml;
}
if($_GET['action'] == 'getproducts')
{
print getProducts();
}
The checkout function within the same php file seems to work, but of course there are no products listed..
I realize that for someone to diagnose the problem they would probably need to download the source files, etc..but I'm stuck.
Any help would be greatly appreciated.
Thanks,
---Yvette
-
Hi,
you are trying to trace the XML in your code, after the place where the error occurs.
Why not trace the urlLoader.data before?
Musicman
-
Hi Musicman,
Actually, the trace statement was already part of the existing code. I'm guessing it was put in there to show how well Flash reads in XML...But I'm confused as to where else I might put that code...I guess I could put in a listener for the ProgressEvent, but I don't know if that would be helpful or not to the problem I'm experiencing..as the trace statement isn't mine...
The problem is the code I'm trying to learn from seems not to work...and I was hoping someone w/experience might have a minute or two to play around with it and figure out why...
Thanks,
---Yvette
-
Code:
function productsLoaded(e:Event):void
{
var urlLoader:URLLoader = URLLoader(e.target);
trace(urlLoader.data);
var xml:XML = new XML(urlLoader.data);
I would hope that a trace at this place might reveal the cause of the problem
Musicman
-
Thanks Musicman,
This is what the trace reveals:
resultCode=LOGGED_IN<products>
<product id="1" name="Cooler Music" desc="Another new one" thumbnail="""" />
</products>resultCode=LOGGED_IN
then I get the error:
TypeError: Error #1090: XML parser failure: element is malformed.
---Yvette
-
Hi Musicman,
So, I see that price was missing from the flashCart.php too..and I have added it in..
However, nothing has changed...that is, my trace statement is still reading the same as before(no new price attribute)..Honestly, I'm not even sure how its connecting with the php being I'm just running it locally in the Flash API.
Help?
Thanks,
---Yvette
-
Actually, it has changed to now include the price in the trace statement. It seems that I have to restart Flash to have it reflect any changes to the php...
I guess its being cached somewhere.
However, I still dont know what is wrong with the XML...Im still getting the element is malformed error....
Thanks,
---Yvette
-
I rewrote the php a bit and now the trace statement outputs this:
<products>
<product id="1" name="Cooler Music" desc="Another new one" thumbnail="""" price="12.95" ></product>
</products>
However, I'm still getting that malformed error...
Help?
Thanks,
---Yvette
-
Got it!--it was the "" in the database for thumbnails
Thanks,
---Yvette
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|