A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Mini shopping cart help

  1. #1
    Senior Member
    Join Date
    Oct 2005
    Posts
    198

    Thumbs down 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

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    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

  3. #3
    Senior Member
    Join Date
    Oct 2005
    Posts
    198
    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

  4. #4
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    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

  5. #5
    Senior Member
    Join Date
    Oct 2005
    Posts
    198
    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

  6. #6
    Senior Member
    Join Date
    Oct 2005
    Posts
    198
    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

  7. #7
    Senior Member
    Join Date
    Oct 2005
    Posts
    198
    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

  8. #8
    Senior Member
    Join Date
    Oct 2005
    Posts
    198
    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

  9. #9
    Senior Member
    Join Date
    Oct 2005
    Posts
    198
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center