Lesson 6: Compiler Problem?

1 view
Skip to first unread message

Ward Bell

unread,
Oct 8, 2009, 2:29:36 PM10/8/09
to Flex 3:Training from the Source
I'm having a unique problem with a bit of code in the referenced
lesson.

Problem: When EComm.mxml is run, the product image is not found so it
show up as "broken." Everything else works as expected.

The problem seems to lie within this block of code, but I cannot
figure out why?

private function prodHandler(event:ResultEvent):void{
var prodArray:Array = new Array();
for each (var p:XML in event.result..product){
var prod:Product = new Product(
Number(p.@catID),
String(p.@prodName),
Number(p.@unitID),
Number(p.@cost),
Number(p.@listPrice),
String(p.@description),
Boolean(p.@isOrganic=="Yes"),
Boolean(p.@isLowFat=="Yes"),
String(p.@imageName));
prodArray.push(prod);
}
groceryInventory = new ArrayCollection(prodArray);
}
When I set a breakpoint and debug the code, I can find the
groceryInventory array, but the imageName shows up as a null:

prodArray Array (@3904a19)
[0] valueObjects.Product (@380add1)
catID 1
cost 4
description "Delicious, low fat Buffalo sirloin. Better tasting
than beef, and better for you too."
imageName null
isLowFat true
isOrganic false
listPrice 6.5
prodName "Buffalo"
unitID 3
[1] valueObjects.Product (@380ae21)
[2] valueObjects.Product (@380ae71)

I checked the xml file that was read and everything is as expected:

<product name="Buffalo" prodName="Buffalo" prodID="7"
unitName="Pound" cost="4" listPrice="6.5"
imageName="meat_buffalo.jpg" description="Delicious, low fat
Buffalo sirloin. Better tasting than beef, and better for you too."
isOrganic="No" isLowFat="Yes"
unitID="3" catName="Meat" catID="1"/>

Why is the grocery array imageName field being populated with null?

Michael Labriola

unread,
Oct 9, 2009, 3:32:15 PM10/9/09
to Flex 3:Training from the Source
Ward,

I don't see anything wrong in the code that you posted here.

Not sure if you have read the debugging chapter at the end of the book
yet, but it might be worthwhile to do so. (it is independent of the
other chapters so it can be read at anytime)

That would then allow you to set a break point in the loop and look at
the expression p.@imageName to see if it contains anything.

Mike

Ward Bell

unread,
Oct 10, 2009, 7:38:05 PM10/10/09
to Flex 3:Training from the Source
Two Things:

1) Found the problem: it was in the Product.as module where I did
not complete the constructor function. When everything worked except
the imageName and when debugging, it showed up as a null, I probably
should have suspected the problem lie in this module somewhere. A
close, line-by-line review showed it was missing.

2) How soon are participant's posts automatically accepted in this
group? With the moderation, it is hard to tell if a post got through
or not. Yesterday, I tried to post what was then my latest findings
before I discovered the solution and that post is not showing up so I
don't really know if it went through or not or if it is just the new
poster delay.

Lesson learned: In some respects, it was a good thing to have this
problem as it made me pay more attention to debugging and
troubleshooting. With finding the actual problem, the next time I
have this sort of problem, I should be better prepared to locate the
problem source.

Ward Bell

unread,
Oct 10, 2009, 12:41:56 AM10/10/09
to Flex 3:Training from the Source
The plot grows thicker:

1) The problem occurred on a machine I use for learning that is not
connected to the Internet. I have Cold Fusion running on that machine
and a webserver. I downloaded the xml files from the web and copied
them to the local server. I modified the calls so the xml was coming
from the local machine. It reads everything else but the imageName
and processes it correctly. As shown above, it shows up correctly
when I display the xml file.

So, I take the finished code from Lesson 6 and run it on a second
machine that is connected to the Internet. It works fine!! The only
thing left to try is to set up some files on the Internet-connected
machine, but with a local server.

I will also look deeper into the debug settings. When I set the
breakpoint after the create groceryInventory array, all of the data
points show up except the imageName -- which shows up as nulls in the
array structure.

The good news/bad news: the experience has lead me to better
understand basic debugging and exploring the wealth of information
returned. It causes me to really appreciate the power of Flex Builder
3 and I anticipate even more power with the new system -- which I'm
running in beta form but have not done alot with it.

The bad news: explaining why this anomoly happens!

On Oct 9, 2:32 pm, Michael Labriola <malabri...@gmail.com> wrote:

Michael Labriola

unread,
Oct 11, 2009, 9:13:28 PM10/11/09
to Flex 3:Training from the Source

From this point on all of your posts should go through automatically.
Reply all
Reply to author
Forward
0 new messages