|
View:
New views
15 Messages
—
Rating Filter:
Alert me
|
|
|
getting the xml data from a dispatched eventI've got an problem when the user clicks on button "Add to Meal" it throws an error because it can't seem to reference the data in mealDetails object inside the com/ directory?
I'm trying to add the item to the list control. I have the code located here in case you want more details http://files.getdropbox.com/u/228472/mealsflex.zip [Bindable] private var customMeals:ArrayCollection = new ArrayCollection; //throws error on this line customMeals.addItem((event.target as mealitem).mealDetails); <?xml version="1.0" encoding="utf-8"?> <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="310" height="320" title="{mealDetails.title}" horizontalAlign="center"> <mx:Metadata> [Event(name="addToMeal")] [Event(name="learnAboutThis")] </mx:Metadata> <mx:Script> <![CDATA[ import mx.controls.Alert; [Bindable] public var mealDetails:Object; private function calldispatch():void { parentApplication.createmeals_loadswf_var = mealDetails.swf; dispatchEvent(new Event('learnAboutThis', true)); } ]]> </mx:Script> <mx:Image source="{'/uploads/nutrition/' + mealDetails.imgsource }" width="285" height="159"/> <mx:Label text="{mealDetails.serving}"/> <mx:Button label="Add to Meal" click="dispatchEvent(new Event('addToMeal', true))"/> <mx:Button label="Learn About This" click="calldispatch()"/> </mx:Panel> |
|
|
Re: getting the xml data from a dispatched eventI'd add a trace statement just before it to see what type of object
event.target is - it could be that the target is the UI component, and not the data object. //throws error on this line trace(event.target); customMeals.addItem((event.target as mealitem).mealDetails); 2009/7/2 Jason B <nospam@...>: > I've got an problem when the user clicks on button "Add to Meal" it throws an error because it can't seem to reference the data in mealDetails object inside the com/ directory? > > I'm trying to add the item to the list control. > > I have the code located here in case you want more details > http://files.getdropbox.com/u/228472/mealsflex.zip > > > [Bindable] > private var customMeals:ArrayCollection = new ArrayCollection; > > //throws error on this line > customMeals.addItem((event.target as mealitem).mealDetails); > > > > > <?xml version="1.0" encoding="utf-8"?> > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="310" height="320" > title="{mealDetails.title}" horizontalAlign="center"> > > > <mx:Metadata> > [Event(name="addToMeal")] > [Event(name="learnAboutThis")] > </mx:Metadata> > > <mx:Script> > <![CDATA[ > import mx.controls.Alert; > > [Bindable] > public var mealDetails:Object; > > > private function calldispatch():void { > parentApplication.createmeals_loadswf_var = mealDetails.swf; > dispatchEvent(new Event('learnAboutThis', true)); > > } > > ]]> > </mx:Script> > > <mx:Image source="{'/uploads/nutrition/' + mealDetails.imgsource }" width="285" height="159"/> > > <mx:Label text="{mealDetails.serving}"/> > > <mx:Button label="Add to Meal" click="dispatchEvent(new Event('addToMeal', true))"/> > > <mx:Button label="Learn About This" click="calldispatch()"/> > > </mx:Panel> > > > > > ------------------------------------ > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Alternative FAQ location: https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847 > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links > > > > |
|
|
Re: getting the xml data from a dispatched eventyes heres the results
"Main0.vsMain.HBox8.VBox968.vsCreateMeals.VBox971.pnlCreateBreakfast.coverflow.Panelcreatemealitem1006" How can I access the object data, it's in a file thats under the folder /com/nutrition/file.mxml --- In flexcoders@..., Sam Lai <samuel.lai@...> wrote: > > I'd add a trace statement just before it to see what type of object > event.target is - it could be that the target is the UI component, and > not the data object. > > //throws error on this line > trace(event.target); > customMeals.addItem((event.target as mealitem).mealDetails); > > 2009/7/2 Jason B <nospam@...>: > > I've got an problem when the user clicks on button "Add to Meal" it throws an error because it can't seem to reference the data in mealDetails object inside the com/ directory? > > > > I'm trying to add the item to the list control. > > > > I have the code located here in case you want more details > > http://files.getdropbox.com/u/228472/mealsflex.zip > > > > > > [Bindable] > > private var customMeals:ArrayCollection = new ArrayCollection; > > > > //throws error on this line > > customMeals.addItem((event.target as mealitem).mealDetails); > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="310" height="320" > > title="{mealDetails.title}" horizontalAlign="center"> > > > > > > <mx:Metadata> > > [Event(name="addToMeal")] > > [Event(name="learnAboutThis")] > > </mx:Metadata> > > > > <mx:Script> > > <![CDATA[ > > import mx.controls.Alert; > > > > [Bindable] > > public var mealDetails:Object; > > > > > > private function calldispatch():void { > > parentApplication.createmeals_loadswf_var = mealDetails.swf; > > dispatchEvent(new Event('learnAboutThis', true)); > > > > } > > > > ]]> > > </mx:Script> > > > > <mx:Image source="{'/uploads/nutrition/' + mealDetails.imgsource }" width="285" height="159"/> > > > > <mx:Label text="{mealDetails.serving}"/> > > > > <mx:Button label="Add to Meal" click="dispatchEvent(new Event('addToMeal', true))"/> > > > > <mx:Button label="Learn About This" click="calldispatch()"/> > > > > </mx:Panel> > > > > > > > > > > ------------------------------------ > > > > -- > > Flexcoders Mailing List > > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > Alternative FAQ location: https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847 > > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links > > > > > > > > > |
|
|
Re: getting the xml data from a dispatched eventany Idea? --- In flexcoders@..., "Jason B" <nospam@...> wrote: > > yes heres the results > "Main0.vsMain.HBox8.VBox968.vsCreateMeals.VBox971.pnlCreateBreakfast.coverflow.Panelcreatemealitem1006" > > How can I access the object data, it's in a file thats under the folder /com/nutrition/file.mxml > > > > --- In flexcoders@..., Sam Lai <samuel.lai@> wrote: > > > > I'd add a trace statement just before it to see what type of object > > event.target is - it could be that the target is the UI component, and > > not the data object. > > > > //throws error on this line > > trace(event.target); > > customMeals.addItem((event.target as mealitem).mealDetails); > > > > 2009/7/2 Jason B <nospam@>: > > > I've got an problem when the user clicks on button "Add to Meal" it throws an error because it can't seem to reference the data in mealDetails object inside the com/ directory? > > > > > > I'm trying to add the item to the list control. > > > > > > I have the code located here in case you want more details > > > http://files.getdropbox.com/u/228472/mealsflex.zip > > > > > > > > > [Bindable] > > > private var customMeals:ArrayCollection = new ArrayCollection; > > > > > > //throws error on this line > > > customMeals.addItem((event.target as mealitem).mealDetails); > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="310" height="320" > > > title="{mealDetails.title}" horizontalAlign="center"> > > > > > > > > > <mx:Metadata> > > > [Event(name="addToMeal")] > > > [Event(name="learnAboutThis")] > > > </mx:Metadata> > > > > > > <mx:Script> > > > <![CDATA[ > > > import mx.controls.Alert; > > > > > > [Bindable] > > > public var mealDetails:Object; > > > > > > > > > private function calldispatch():void { > > > parentApplication.createmeals_loadswf_var = mealDetails.swf; > > > dispatchEvent(new Event('learnAboutThis', true)); > > > > > > } > > > > > > ]]> > > > </mx:Script> > > > > > > <mx:Image source="{'/uploads/nutrition/' + mealDetails.imgsource }" width="285" height="159"/> > > > > > > <mx:Label text="{mealDetails.serving}"/> > > > > > > <mx:Button label="Add to Meal" click="dispatchEvent(new Event('addToMeal', true))"/> > > > > > > <mx:Button label="Learn About This" click="calldispatch()"/> > > > > > > </mx:Panel> > > > > > > > > > > > > > > > ------------------------------------ > > > > > > -- > > > Flexcoders Mailing List > > > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > > Alternative FAQ location: https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847 > > > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links > > > > > > > > > > > > > > > |
|
|
Re: getting the xml data from a dispatched eventThe zip file doesn't contain any code in the src folder. Kind of hard to see what's happening without it. -TH --- In flexcoders@..., "Jason B" <nospam@...> wrote: > > > any Idea? > > > > --- In flexcoders@..., "Jason B" nospam@ wrote: > > > > yes heres the results > > erflow.Panelcreatemealitem1006" > > > > How can I access the object data, it's in a file thats under the folder /com/nutrition/file.mxml > > > > > > > > --- In flexcoders@..., Sam Lai <samuel.lai@> wrote: > > > > > > I'd add a trace statement just before it to see what type of object > > > event.target is - it could be that the target is the UI component, and > > > not the data object. > > > > > > //throws error on this line > > > trace(event.target); > > > customMeals.addItem((event.target as mealitem).mealDetails); > > > > > > 2009/7/2 Jason B <nospam@>: > > > > I've got an problem when the user clicks on button "Add to Meal" it throws an error because it can't seem to reference the data in mealDetails object inside the com/ directory? > > > > > > > > I'm trying to add the item to the list control. > > > > > > > > I have the code located here in case you want more details > > > > http://files.getdropbox.com/u/228472/mealsflex.zip > > > > > > > > > > > > [Bindable] > > > > private var customMeals:ArrayCollection = new ArrayCollection; > > > > > > > > //throws error on this line > > > > customMeals.addItem((event.target as mealitem).mealDetails); > > > > > > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="310" > > > > title="{mealDetails.title}" horizontalAlign="center"> > > > > > > > > > > > > <mx:Metadata> > > > > [Event(name="addToMeal")] > > > > [Event(name="learnAboutThis")] > > > > </mx:Metadata> > > > > > > > > <mx:Script> > > > > <![CDATA[ > > > > import mx.controls.Alert; > > > > > > > > [Bindable] > > > > public var mealDetails:Object; > > > > > > > > > > > > private function calldispatch():void { > > > > > > > > dispatchEvent(new Event('learnAboutThis', true)); > > > > > > > > } > > > > > > > > ]]> > > > > </mx:Script> > > > > > > > > <mx:Image source="{'/uploads/nutrition/' + mealDetails.imgsource }" width="285" height="159"/> > > > > > > > > <mx:Label text="{mealDetails.serving}"/> > > > > > > > > <mx:Button label="Add to Meal" click="dispatchEvent(new Event('addToMeal', true))"/> > > > > > > > > <mx:Button label="Learn About This" click="calldispatch()"/> > > > > > > > > </mx:Panel> > > > > > > > > > > > > > > > > > > > > ------------------------------------ > > > > > > > > -- > > > > Flexcoders Mailing List > > > > FAQ: > > > > Alternative FAQ location: https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-\ 1e62079f6847 > > > > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links > > > > > > > > > > > > > > > > > > > > > > |
|
|
Re: Re: getting the xml data from a dispatched eventIt seems like wherever this code is -
[Bindable] private var customMeals:ArrayCollection = new ArrayCollection; //throws error on this line customMeals.addItem((event.target as mealitem).mealDetails); event.target is actually the panel containing the 'create meal item' button, as opposed to the mealitem itself. Can you post some more of the script and MXML for that part? The src folder is empty for me too in the ZIP file. 2009/7/2 Jason B <nospam@...>: > yes heres the results > "Main0.vsMain.HBox8.VBox968.vsCreateMeals.VBox971.pnlCreateBreakfast.coverflow.Panelcreatemealitem1006" > > How can I access the object data, it's in a file thats under the folder /com/nutrition/file.mxml > > > > --- In flexcoders@..., Sam Lai <samuel.lai@...> wrote: >> >> I'd add a trace statement just before it to see what type of object >> event.target is - it could be that the target is the UI component, and >> not the data object. >> >> //throws error on this line >> trace(event.target); >> customMeals.addItem((event.target as mealitem).mealDetails); >> >> 2009/7/2 Jason B <nospam@...>: >> > I've got an problem when the user clicks on button "Add to Meal" it throws an error because it can't seem to reference the data in mealDetails object inside the com/ directory? >> > >> > I'm trying to add the item to the list control. >> > >> > I have the code located here in case you want more details >> > http://files.getdropbox.com/u/228472/mealsflex.zip >> > >> > >> > [Bindable] >> > private var customMeals:ArrayCollection = new ArrayCollection; >> > >> > //throws error on this line >> > customMeals.addItem((event.target as mealitem).mealDetails); >> > >> > >> > >> > >> > <?xml version="1.0" encoding="utf-8"?> >> > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="310" height="320" >> > title="{mealDetails.title}" horizontalAlign="center"> >> > >> > >> > <mx:Metadata> >> > [Event(name="addToMeal")] >> > [Event(name="learnAboutThis")] >> > </mx:Metadata> >> > >> > <mx:Script> >> > <![CDATA[ >> > import mx.controls.Alert; >> > >> > [Bindable] >> > public var mealDetails:Object; >> > >> > >> > private function calldispatch():void { >> > parentApplication.createmeals_loadswf_var = mealDetails.swf; >> > dispatchEvent(new Event('learnAboutThis', true)); >> > >> > } >> > >> > ]]> >> > </mx:Script> >> > >> > <mx:Image source="{'/uploads/nutrition/' + mealDetails.imgsource }" width="285" height="159"/> >> > >> > <mx:Label text="{mealDetails.serving}"/> >> > >> > <mx:Button label="Add to Meal" click="dispatchEvent(new Event('addToMeal', true))"/> >> > >> > <mx:Button label="Learn About This" click="calldispatch()"/> >> > >> > </mx:Panel> >> > >> > >> > >> > >> > ------------------------------------ >> > >> > -- >> > Flexcoders Mailing List >> > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt >> > Alternative FAQ location: https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847 >> > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links >> > >> > >> > >> > >> > > > > > ------------------------------------ > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Alternative FAQ location: https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847 > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links > > > > |
|
|
Re: getting the xml data from a dispatched eventHeres my three mxml files two of which are under the com/ folder and get imported...hope that helps
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()" styleName="plain" xmlns:nutrition="com.nutrition.*" paddingLeft="10" paddingTop="10" paddingRight="10" paddingBottom="10"> <mx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.collections.ICollectionView; import mx.collections.XMLListCollection; import com.nutrition.MealItem; import mx.controls.Alert; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.rpc.http.HTTPService; // initialize private function init():void { //load calories httpservice_load("/main.php/flexnutrition/loadcalories", this["loadcaloriesResultHandler"]); hsNutrition.send(); addEventListener('addToMeal', addToMealHandler); addEventListener('removeMeal', removeMealHandler); addEventListener('learnAboutThis', learnaboutthisswf); } private function httpservice_load(url_src:String, resulthandler:Function):void{ httpService.url = url_src; //var tmp:String = resulthandler.toString(); //if(tmp != "none") httpService.addEventListener(ResultEvent.RESULT, resulthandler); httpService.send(); } private function learnaboutthisswf(event:Event):void{ vfc_guy.load("/uploads/swf/" + loadswf_var); } [Bindable] private var nutritionData:XML; [Bindable] private var maindata:XML; [Bindable] public var loadswf_var:String; [Bindable] public var createmeals_loadswf_var:String; //load all calories for main meals private function loadcaloriesResultHandler(event:ResultEvent):void { maindata = event.result as XML; vfc_guy.load("/uploads/swf/" + maindata.swf); } // nutrition result handler private function nutritionResultHandler(event:ResultEvent):void { nutritionData = event.result as XML; } // nutrition fault handler private function nutritionFaultHandler(event:FaultEvent):void { Alert.show(event.toString()); } // create breakfast private function createBreakfast():void { vsMain.selectedIndex = 1; plantype = 'Breakfast'; } // create lunch private function createLunch():void { vsMain.selectedIndex = 1; plantype = 'Lunch'; } // create dinner private function createDinner():void { vsMain.selectedIndex = 1; plantype = 'Dinner'; } [Bindable] private var plantype:String; [Bindable] private var customMeals:ArrayCollection = new ArrayCollection; // addToMeal event Handler private function addToMealHandler(event:Event):void { trace(event.target); //customMeals.addItem((event.target as mealitem).mealDetails); Alert.show(event.toString()); } // removeMeal event Handler private function removeMealHandler(event:Event):void { customMeals.removeItemAt(ls.selectedIndex); } ]]> </mx:Script> <mx:HTTPService id="hsNutrition" url="/main.php/flexnutrition/nutritioncal" result="nutritionResultHandler(event)" fault="nutritionFaultHandler(event)" resultFormat="e4x"/> <mx:HTTPService id="httpService" url="" resultFormat="e4x"/> <mx:Label id="totalcalories" text="{'Today\'s Meal Plan is based on a ' + maindata.totalcalories + ' Calorie Diet'}" fontWeight="bold" fontSize="18"/> <!--mx:Button label="Print Meal Menu" /--> <mx:ViewStack id="vsMain" width="100%" height="100%"> <mx:Canvas id="nutrition_canvas" width="100%" height="100%"> <mx:SWFLoader id="vfc_guy" source="" height="400" width="400" autoLoad="true" x="700" y="100" /> <mx:HBox width="100%" height="100%"> <mx:VBox width="40%" height="100%"> <nutrition:MealPanel id="pnlBreakfast" meal="{nutritionData.breakfast}" title="Breakfast : Please select one meal from below({maindata.breakfast} Cal Goal)"/> <mx:HBox horizontalCenter="right"> <mx:Button label="Create your own Breakfast" click="createBreakfast()"/> </mx:HBox> <nutrition:MealPanel id="pnlSnack1" meal="{nutritionData.snack1}" title="Snack : Please select one snack from below({maindata.snack1} Cal Goal)"/> <!--mx:Button label="Create your own Lunch" click="createLunch()"/--> <nutrition:MealPanel id="pnlLunch" meal="{nutritionData.lunch}" title="Lunch : Please select one meal from below({maindata.lunch} Cal Goal)"/> <nutrition:MealPanel id="pnlSnack2" meal="{nutritionData.snack2}" title="Snack : Please select one snack from below({maindata.snack2} Cal Goal)"/> <!--mx:Button label="Create your own Dinner" click="createDinner()"/--> <nutrition:MealPanel id="pnlDinner" meal="{nutritionData.dinner}" title="Dinner : Please select one meal from below({maindata.dinner} Cal Goal)"/> <nutrition:MealPanel id="pnlSnack3" meal="{nutritionData.snack3}" title="Snack : Please select one snack from below({maindata.snack3} Cal Goal)"/> </mx:VBox> </mx:HBox> </mx:Canvas> <mx:HBox width="100%" height="100%"> <mx:VBox width="30%" height="100%"> <mx:HBox> <mx:Label text="{'My Custom ' + plantype}"/> </mx:HBox> <mx:List id="ls" dataProvider="{customMeals}" width="100%"> <mx:itemRenderer> <mx:Component> <mx:VBox> <mx:Image width="100" height="100"/> <mx:Button label="Remove" click="dispatchEvent(new Event('removeMeal', true))"/> <mx:Label text="{data.serving}"/> </mx:VBox> </mx:Component> </mx:itemRenderer> </mx:List> </mx:VBox> <mx:VBox width="100%" height="100%"> <!--mx:Label text="Please select ONE ITEM from list below"/--> <mx:ViewStack width="40%" height="410" borderStyle="inset" borderThickness="2" id="vsCreateMeals"> <mx:VBox > <nutrition:Panelcreatemeal id="pnlCreateBreakfast" meal="{nutritionData.breakfast}"/> </mx:VBox> <mx:VBox > <nutrition:Panelcreatemeal id="pnlCreateLunch" meal="{nutritionData.lunch}"/> </mx:VBox> <mx:VBox > <nutrition:Panelcreatemeal id="pnlCreateDinner" meal="{nutritionData.dinner}"/> </mx:VBox> </mx:ViewStack> <mx:HBox> <mx:Button label="Save" click="vsMain.selectedIndex = 0;"/> <mx:Button label="Cancel" click="vsMain.selectedIndex = 0;"/> </mx:HBox> </mx:VBox> </mx:HBox> </mx:ViewStack> </mx:Application> <?xml version="1.0" encoding="utf-8"?> <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="390" borderThicknessLeft="0" borderThicknessRight="0" borderThicknessBottom="0" dropShadowEnabled="false" horizontalAlign="center" xmlns:containers="com.dougmccune.containers.*" title="Select An Item from below"> <mx:Script> <![CDATA[ //import com.createmealPanel; [Bindable] private var _meal:XMLList; public function set meal(value:XMLList):void { if(value) { _meal = value; createContainers(); } } private function createContainers():void { for each(var item:Object in _meal.itemdata) { if(item.available == "yes") { var mealitem:Panelcreatemealitem = new Panelcreatemealitem; coverflow.addChild(mealitem); mealitem.mealDetails = item; } } } ]]> </mx:Script> <containers:CoverFlowContainer id="coverflow" width="100%" height="100%" horizontalGap="1" borderStyle="inset" backgroundColor="0xFFFFFF" segments="9" reflectionEnabled="true"/> <mx:HBox> <mx:Button label="item 1" click="parentApplication.vsCreateMeals.selectedIndex=0;"/> <mx:Button label="side item 1" click="parentApplication.vsCreateMeals.selectedIndex=1;"/> <mx:Button label="side item 2" click="parentApplication.vsCreateMeals.selectedIndex=2;"/> </mx:HBox> </mx:Panel> <?xml version="1.0" encoding="utf-8"?> <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="310" height="320" title="{mealDetails.title}" horizontalAlign="center"> <mx:Metadata> [Event(name="addToMeal")] [Event(name="learnAboutThis")] </mx:Metadata> <mx:Script> <![CDATA[ import mx.controls.Alert; [Bindable] public var mealDetails:Object; private function calldispatch():void { parentApplication.createmeals_loadswf_var = mealDetails.swf; dispatchEvent(new Event('learnAboutThis', true)); } ]]> </mx:Script> <mx:Image source="{'/uploads/nutrition/' + mealDetails.imgsource }" width="285" height="159"/> <mx:Label text="{mealDetails.serving}"/> <mx:Button label="Add to Meal" click="dispatchEvent(new Event('addToMeal', true))"/> <mx:Button label="Learn About This" click="calldispatch()"/> </mx:Panel> --- In flexcoders@..., Sam Lai <samuel.lai@...> wrote: > > It seems like wherever this code is - > > [Bindable] > private var customMeals:ArrayCollection = new ArrayCollection; > > //throws error on this line > customMeals.addItem((event.target as mealitem).mealDetails); > > event.target is actually the panel containing the 'create meal item' > button, as opposed to the mealitem itself. Can you post some more of > the script and MXML for that part? > > The src folder is empty for me too in the ZIP file. > > 2009/7/2 Jason B <nospam@...>: > > yes heres the results > > "Main0.vsMain.HBox8.VBox968.vsCreateMeals.VBox971.pnlCreateBreakfast.coverflow.Panelcreatemealitem1006" > > > > How can I access the object data, it's in a file thats under the folder /com/nutrition/file.mxml > > > > > > > > --- In flexcoders@..., Sam Lai <samuel.lai@> wrote: > >> > >> I'd add a trace statement just before it to see what type of object > >> event.target is - it could be that the target is the UI component, and > >> not the data object. > >> > >> //throws error on this line > >> trace(event.target); > >> customMeals.addItem((event.target as mealitem).mealDetails); > >> > >> 2009/7/2 Jason B <nospam@>: > >> > I've got an problem when the user clicks on button "Add to Meal" it throws an error because it can't seem to reference the data in mealDetails object inside the com/ directory? > >> > > >> > I'm trying to add the item to the list control. > >> > > >> > I have the code located here in case you want more details > >> > http://files.getdropbox.com/u/228472/mealsflex.zip > >> > > >> > > >> > [Bindable] > >> > private var customMeals:ArrayCollection = new ArrayCollection; > >> > > >> > //throws error on this line > >> > customMeals.addItem((event.target as mealitem).mealDetails); > >> > > >> > > >> > > >> > > >> > <?xml version="1.0" encoding="utf-8"?> > >> > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="310" height="320" > >> > title="{mealDetails.title}" horizontalAlign="center"> > >> > > >> > > >> > <mx:Metadata> > >> > [Event(name="addToMeal")] > >> > [Event(name="learnAboutThis")] > >> > </mx:Metadata> > >> > > >> > <mx:Script> > >> > <![CDATA[ > >> > import mx.controls.Alert; > >> > > >> > [Bindable] > >> > public var mealDetails:Object; > >> > > >> > > >> > private function calldispatch():void { > >> > parentApplication.createmeals_loadswf_var = mealDetails.swf; > >> > dispatchEvent(new Event('learnAboutThis', true)); > >> > > >> > } > >> > > >> > ]]> > >> > </mx:Script> > >> > > >> > <mx:Image source="{'/uploads/nutrition/' + mealDetails.imgsource }" width="285" height="159"/> > >> > > >> > <mx:Label text="{mealDetails.serving}"/> > >> > > >> > <mx:Button label="Add to Meal" click="dispatchEvent(new Event('addToMeal', true))"/> > >> > > >> > <mx:Button label="Learn About This" click="calldispatch()"/> > >> > > >> > </mx:Panel> > >> > > >> > > >> > > >> > > >> > ------------------------------------ > >> > > >> > -- > >> > Flexcoders Mailing List > >> > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > >> > Alternative FAQ location: https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847 > >> > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links > >> > > >> > > >> > > >> > > >> > > > > > > > > > > ------------------------------------ > > > > -- > > Flexcoders Mailing List > > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > Alternative FAQ location: https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847 > > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links > > > > > > > > > |
|
|
Re: getting the xml data from a dispatched eventWow, I've got to say; "What a mess." However, you can get it to work with the following changes: [Bindable] private var customMeals:XMLListCollection = new XMLListCollection(); // addToMeal event Handler private function addToMealHandler(event:Event):void { customMeals.addItem((event.target as Panelcreatemealitem).mealDetails); Alert.show(customMeals.toString()); } You have some naming conflicts and, since you're dealing with xml, you'll need to use an XMLListCollection; instead of an ArrayCollection. -TH --- In flexcoders@..., "Jason B" <nospam@...> wrote: > > Heres my three mxml files two of which are under the com/ folder and get imported...hope that helps > > > <?xml version="1.0" encoding="utf-8"?> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" > creationComplete="init()" styleName="plain" xmlns:nutrition="com.nutrition.*" > paddingLeft="10" paddingTop="10" paddingRight="10" paddingBottom="10"> > > <mx:Script> > <![CDATA[ > import mx.collections.ArrayCollection; > import mx.collections.ICollectionView; > import mx.collections.XMLListCollection; > import com.nutrition.MealItem; > import mx.controls.Alert; > import mx.rpc.events.FaultEvent; > import mx.rpc.events.ResultEvent; > import mx.rpc.http.HTTPService; > // initialize > private function init():void > { > //load calories > httpservice_load("/main.php/flexnutrition/loadcalories", > > hsNutrition.send(); > addEventListener('addToMeal', addToMealHandler); > addEventListener('removeMeal', removeMealHandler); > addEventListener('learnAboutThis', learnaboutthisswf); > > > > } > > private function httpservice_load(url_src:String, > > httpService.url = url_src; > > //var tmp:String = resulthandler.toString(); > //if(tmp != "none") > httpService.addEventListener(ResultEvent.RESULT, resulthandler); > httpService.send(); > } > > private function learnaboutthisswf(event:Event):void{ > vfc_guy.load("/uploads/swf/" + loadswf_var); > > } > > [Bindable] > private var nutritionData:XML; > [Bindable] > private var maindata:XML; > [Bindable] > public var loadswf_var:String; > [Bindable] > public var createmeals_loadswf_var:String; > > //load all calories for main meals > private function loadcaloriesResultHandler(event:ResultEvent):void > { > maindata = event.result as XML; > vfc_guy.load("/uploads/swf/" + maindata.swf); > } > > // nutrition result handler > private function nutritionResultHandler(event:ResultEvent):void > { > nutritionData = event.result as XML; > } > // nutrition fault handler > private function nutritionFaultHandler(event:FaultEvent):void > { > Alert.show(event.toString()); > } > > // create breakfast > private function createBreakfast():void > { > vsMain.selectedIndex = 1; > plantype = 'Breakfast'; > } > // create lunch > private function createLunch():void > { > vsMain.selectedIndex = 1; > plantype = 'Lunch'; > } > // create dinner > private function createDinner():void > { > vsMain.selectedIndex = 1; > plantype = 'Dinner'; > } > > [Bindable] > private var plantype:String; > > [Bindable] > private var customMeals:ArrayCollection = new ArrayCollection; > > // addToMeal event Handler > private function addToMealHandler(event:Event):void > { > trace(event.target); > //customMeals.addItem((event.target as mealitem).mealDetails); > Alert.show(event.toString()); > > } > > // removeMeal event Handler > private function removeMealHandler(event:Event):void > { > customMeals.removeItemAt(ls.selectedIndex); > } > > ]]> > </mx:Script> > > <mx:HTTPService id="hsNutrition" > result="nutritionResultHandler(event)" > fault="nutritionFaultHandler(event)" resultFormat="e4x"/> > > <mx:HTTPService id="httpService" url="" resultFormat="e4x"/> > > <mx:Label id="totalcalories" text="{'Today\'s Meal Plan is based on a ' + maindata.totalcalories + ' Calorie Diet'}" fontWeight="bold" fontSize="18"/> > > <!--mx:Button label="Print Meal Menu" /--> > > <mx:ViewStack id="vsMain" width="100%" height="100%"> > > <mx:Canvas id="nutrition_canvas" width="100%" height="100%"> > > <mx:SWFLoader id="vfc_guy" source="" height="400" width="400" autoLoad="true" x="700" y="100" /> > > <mx:HBox width="100%" height="100%"> > > <mx:VBox width="40%" height="100%"> > > <nutrition:MealPanel id="pnlBreakfast" meal="{nutritionData.breakfast}" > title="Breakfast : Please select one meal from below({maindata.breakfast} Cal Goal)"/> > > <mx:HBox horizontalCenter="right"> > <mx:Button label="Create your own Breakfast" click="createBreakfast()"/> > </mx:HBox> > > > <nutrition:MealPanel id="pnlSnack1" meal="{nutritionData.snack1}" > title="Snack : Please select one snack from below({maindata.snack1} Cal Goal)"/> > <!--mx:Button label="Create your own Lunch" click="createLunch()"/--> > > <nutrition:MealPanel id="pnlLunch" meal="{nutritionData.lunch}" > title="Lunch : Please select one meal from below({maindata.lunch} Cal Goal)"/> > > <nutrition:MealPanel id="pnlSnack2" meal="{nutritionData.snack2}" > title="Snack : Please select one snack from below({maindata.snack2} Cal Goal)"/> > <!--mx:Button label="Create your own Dinner" click="createDinner()"/--> > > <nutrition:MealPanel id="pnlDinner" meal="{nutritionData.dinner}" > title="Dinner : Please select one meal from below({maindata.dinner} Cal Goal)"/> > > <nutrition:MealPanel id="pnlSnack3" meal="{nutritionData.snack3}" > title="Snack : Please select one snack from below({maindata.snack3} Cal Goal)"/> > </mx:VBox> > > > </mx:HBox> > </mx:Canvas> > > > <mx:HBox width="100%" height="100%"> > > <mx:VBox width="30%" height="100%"> > <mx:HBox> > <mx:Label text="{'My Custom ' + plantype}"/> > > </mx:HBox> > > <mx:List id="ls" dataProvider="{customMeals}" width="100%"> > <mx:itemRenderer> > <mx:Component> > <mx:VBox> > <mx:Image width="100" height="100"/> > <mx:Button label="Remove" click="dispatchEvent(new Event('removeMeal', > <mx:Label text="{data.serving}"/> > </mx:VBox> > </mx:Component> > </mx:itemRenderer> > </mx:List> > </mx:VBox> > > <mx:VBox width="100%" height="100%"> > > <!--mx:Label text="Please select ONE ITEM from list below"/--> > <mx:ViewStack width="40%" height="410" borderStyle="inset" > > <mx:VBox > > <nutrition:Panelcreatemeal id="pnlCreateBreakfast" meal="{nutritionData.breakfast}"/> > </mx:VBox> > > <mx:VBox > > <nutrition:Panelcreatemeal id="pnlCreateLunch" meal="{nutritionData.lunch}"/> > </mx:VBox> > > <mx:VBox > > <nutrition:Panelcreatemeal id="pnlCreateDinner" meal="{nutritionData.dinner}"/> > </mx:VBox> > > </mx:ViewStack> > <mx:HBox> > <mx:Button label="Save" click="vsMain.selectedIndex = 0;"/> > <mx:Button label="Cancel" click="vsMain.selectedIndex = 0;"/> > </mx:HBox> > > </mx:VBox> > > > </mx:HBox> > > </mx:ViewStack> > > </mx:Application> > > > > > > <?xml version="1.0" encoding="utf-8"?> > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" > borderThicknessLeft="0" borderThicknessRight="0" borderThicknessBottom="0" > dropShadowEnabled="false" > horizontalAlign="center" xmlns:containers="com.dougmccune.containers.*" title="Select An Item from below"> > > <mx:Script> > <![CDATA[ > //import com.createmealPanel; > > [Bindable] > private var _meal:XMLList; > > public function set meal(value:XMLList):void > { > if(value) > { > _meal = value; > createContainers(); > } > } > > private function createContainers():void > { > for each(var item:Object in _meal.itemdata) > { > if(item.available == "yes") > { > var mealitem:Panelcreatemealitem = new Panelcreatemealitem; > coverflow.addChild(mealitem); > mealitem.mealDetails = item; > } > } > } > ]]> > </mx:Script> > > <containers:CoverFlowContainer id="coverflow" width="100%" > horizontalGap="1" borderStyle="inset" backgroundColor="0xFFFFFF" > segments="9" reflectionEnabled="true"/> > > <mx:HBox> > <mx:Button label="item 1" click="parentApplication.vsCreateMeals.selectedIndex=0;"/> > <mx:Button label="side item 1" click="parentApplication.vsCreateMeals.selectedIndex=1;"/> > <mx:Button label="side item 2" click="parentApplication.vsCreateMeals.selectedIndex=2;"/> > </mx:HBox> > </mx:Panel> > > > > > <?xml version="1.0" encoding="utf-8"?> > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="310" height="320" > title="{mealDetails.title}" horizontalAlign="center"> > > > <mx:Metadata> > [Event(name="addToMeal")] > [Event(name="learnAboutThis")] > </mx:Metadata> > > <mx:Script> > <![CDATA[ > import mx.controls.Alert; > > [Bindable] > public var mealDetails:Object; > > > private function calldispatch():void { > parentApplication.createmeals_loadswf_var = mealDetails.swf; > dispatchEvent(new Event('learnAboutThis', true)); > > } > > ]]> > </mx:Script> > > <mx:Image source="{'/uploads/nutrition/' + mealDetails.imgsource }" > > <mx:Label text="{mealDetails.serving}"/> > > <mx:Button label="Add to Meal" click="dispatchEvent(new Event('addToMeal', true))"/> > > <mx:Button label="Learn About This" click="calldispatch()"/> > > </mx:Panel> > > > > --- In flexcoders@..., Sam Lai samuel.lai@ wrote: > > > > It seems like wherever this code is - > > > > [Bindable] > > private var customMeals:ArrayCollection = new ArrayCollection; > > > > //throws error on this line > > customMeals.addItem((event.target as mealitem).mealDetails); > > > > event.target is actually the panel containing the 'create meal item' > > button, as opposed to the mealitem itself. Can you post some more of > > the script and MXML for that part? > > > > The src folder is empty for me too in the ZIP file. > > > > 2009/7/2 Jason B nospam@: > > > yes heres the results > > > erflow.Panelcreatemealitem1006" > > > > > > How can I access the object data, it's in a file thats under the folder /com/nutrition/file.mxml > > > > > > > > > > > > --- In flexcoders@..., Sam Lai <samuel.lai@> wrote: > > >> > > >> I'd add a trace statement just before it to see what type of object > > >> event.target is - it could be that the target is the UI component, and > > >> not the data object. > > >> > > >> //throws error on this line > > >> trace(event.target); > > >> customMeals.addItem((event.target as mealitem).mealDetails); > > >> > > >> 2009/7/2 Jason B <nospam@>: > > >> > I've got an problem when the user clicks on button "Add to Meal" it throws an error because it can't seem to reference the data in mealDetails object inside the com/ directory? > > >> > > > >> > I'm trying to add the item to the list control. > > >> > > > >> > I have the code located here in case you want more details > > >> > http://files.getdropbox.com/u/228472/mealsflex.zip > > >> > > > >> > > > >> > [Bindable] > > >> > private var customMeals:ArrayCollection = new ArrayCollection; > > >> > > > >> > //throws error on this line > > >> > customMeals.addItem((event.target as mealitem).mealDetails); > > >> > > > >> > > > >> > > > >> > > > >> > <?xml version="1.0" encoding="utf-8"?> > > >> > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="310" > > >> > title="{mealDetails.title}" horizontalAlign="center"> > > >> > > > >> > > > >> > <mx:Metadata> > > >> > [Event(name="addToMeal")] > > >> > [Event(name="learnAboutThis")] > > >> > </mx:Metadata> > > >> > > > >> > <mx:Script> > > >> > <![CDATA[ > > >> > import mx.controls.Alert; > > >> > > > >> > [Bindable] > > >> > public var mealDetails:Object; > > >> > > > >> > > > >> > private function calldispatch():void { > > >> > > > >> > dispatchEvent(new Event('learnAboutThis', true)); > > >> > > > >> > } > > >> > > > >> > ]]> > > >> > </mx:Script> > > >> > > > >> > <mx:Image source="{'/uploads/nutrition/' + mealDetails.imgsource }" width="285" height="159"/> > > >> > > > >> > <mx:Label text="{mealDetails.serving}"/> > > >> > > > >> > <mx:Button label="Add to Meal" click="dispatchEvent(new Event('addToMeal', true))"/> > > >> > > > >> > <mx:Button label="Learn About This" click="calldispatch()"/> > > >> > > > >> > </mx:Panel> > > >> > > > >> > > > >> > > > >> > > > >> > ------------------------------------ > > >> > > > >> > -- > > >> > Flexcoders Mailing List > > >> > FAQ: > > >> > Alternative FAQ location: https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-\ 1e62079f6847 > > >> > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links > > >> > > > >> > > > >> > > > >> > > > >> > > > > > > > > > > > > > > > ------------------------------------ > > > > > > -- > > > Flexcoders Mailing List > > > FAQ: > > > Alternative FAQ location: https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-\ 1e62079f6847 > > > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links > > > > > > > > > > > > > > > |
|
|
Re: getting the xml data from a dispatched eventIt wont accept your suggestions Severity and Description Path Resource Location Creation Time Id 1120: Access of undefined property Panelcreatemealitem. /src Main.mxml line 105 1246801954900 468962 --- In flexcoders@..., "Tim Hoff" <TimHoff@...> wrote: > > > Wow, I've got to say; "What a mess." However, you can get it to work > with the following changes: > > [Bindable] > private var customMeals:XMLListCollection = new XMLListCollection(); > > > > // addToMeal event Handler > private function addToMealHandler(event:Event):void > { > customMeals.addItem((event.target as > Panelcreatemealitem).mealDetails); > Alert.show(customMeals.toString()); > } > > You have some naming conflicts and, since you're dealing with xml, > you'll need to use an XMLListCollection; instead of an ArrayCollection. > > -TH > > --- In flexcoders@..., "Jason B" <nospam@> wrote: > > > > Heres my three mxml files two of which are under the com/ folder and > get imported...hope that helps > > > > > > <?xml version="1.0" encoding="utf-8"?> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > layout="vertical" > > creationComplete="init()" styleName="plain" > xmlns:nutrition="com.nutrition.*" > > paddingLeft="10" paddingTop="10" paddingRight="10" paddingBottom="10"> > > > > <mx:Script> > > <![CDATA[ > > import mx.collections.ArrayCollection; > > import mx.collections.ICollectionView; > > import mx.collections.XMLListCollection; > > import com.nutrition.MealItem; > > import mx.controls.Alert; > > import mx.rpc.events.FaultEvent; > > import mx.rpc.events.ResultEvent; > > import mx.rpc.http.HTTPService; > > // initialize > > private function init():void > > { > > //load calories > > httpservice_load("/main.php/flexnutrition/loadcalories", > this["loadcaloriesResultHandler"]); > > > > hsNutrition.send(); > > addEventListener('addToMeal', addToMealHandler); > > addEventListener('removeMeal', removeMealHandler); > > addEventListener('learnAboutThis', learnaboutthisswf); > > > > > > > > } > > > > private function httpservice_load(url_src:String, > resulthandler:Function):void{ > > > > httpService.url = url_src; > > > > //var tmp:String = resulthandler.toString(); > > //if(tmp != "none") > > httpService.addEventListener(ResultEvent.RESULT, resulthandler); > > httpService.send(); > > } > > > > private function learnaboutthisswf(event:Event):void{ > > vfc_guy.load("/uploads/swf/" + loadswf_var); > > > > } > > > > [Bindable] > > private var nutritionData:XML; > > [Bindable] > > private var maindata:XML; > > [Bindable] > > public var loadswf_var:String; > > [Bindable] > > public var createmeals_loadswf_var:String; > > > > //load all calories for main meals > > private function loadcaloriesResultHandler(event:ResultEvent):void > > { > > maindata = event.result as XML; > > vfc_guy.load("/uploads/swf/" + maindata.swf); > > } > > > > // nutrition result handler > > private function nutritionResultHandler(event:ResultEvent):void > > { > > nutritionData = event.result as XML; > > } > > // nutrition fault handler > > private function nutritionFaultHandler(event:FaultEvent):void > > { > > Alert.show(event.toString()); > > } > > > > // create breakfast > > private function createBreakfast():void > > { > > vsMain.selectedIndex = 1; > > plantype = 'Breakfast'; > > } > > // create lunch > > private function createLunch():void > > { > > vsMain.selectedIndex = 1; > > plantype = 'Lunch'; > > } > > // create dinner > > private function createDinner():void > > { > > vsMain.selectedIndex = 1; > > plantype = 'Dinner'; > > } > > > > [Bindable] > > private var plantype:String; > > > > [Bindable] > > private var customMeals:ArrayCollection = new ArrayCollection; > > > > // addToMeal event Handler > > private function addToMealHandler(event:Event):void > > { > > trace(event.target); > > //customMeals.addItem((event.target as mealitem).mealDetails); > > Alert.show(event.toString()); > > > > } > > > > // removeMeal event Handler > > private function removeMealHandler(event:Event):void > > { > > customMeals.removeItemAt(ls.selectedIndex); > > } > > > > ]]> > > </mx:Script> > > > > <mx:HTTPService id="hsNutrition" > url="/main.php/flexnutrition/nutritioncal" > > result="nutritionResultHandler(event)" > > fault="nutritionFaultHandler(event)" resultFormat="e4x"/> > > > > <mx:HTTPService id="httpService" url="" resultFormat="e4x"/> > > > > <mx:Label id="totalcalories" text="{'Today\'s Meal Plan is based on a > ' + maindata.totalcalories + ' Calorie Diet'}" fontWeight="bold" > fontSize="18"/> > > > > <!--mx:Button label="Print Meal Menu" /--> > > > > <mx:ViewStack id="vsMain" width="100%" height="100%"> > > > > <mx:Canvas id="nutrition_canvas" width="100%" height="100%"> > > > > <mx:SWFLoader id="vfc_guy" source="" height="400" width="400" > autoLoad="true" x="700" y="100" /> > > > > <mx:HBox width="100%" height="100%"> > > > > <mx:VBox width="40%" height="100%"> > > > > <nutrition:MealPanel id="pnlBreakfast" > meal="{nutritionData.breakfast}" > > title="Breakfast : Please select one meal from > below({maindata.breakfast} Cal Goal)"/> > > > > <mx:HBox horizontalCenter="right"> > > <mx:Button label="Create your own Breakfast" > click="createBreakfast()"/> > > </mx:HBox> > > > > > > <nutrition:MealPanel id="pnlSnack1" meal="{nutritionData.snack1}" > > title="Snack : Please select one snack from below({maindata.snack1} > Cal Goal)"/> > > <!--mx:Button label="Create your own Lunch" click="createLunch()"/--> > > > > <nutrition:MealPanel id="pnlLunch" meal="{nutritionData.lunch}" > > title="Lunch : Please select one meal from below({maindata.lunch} Cal > Goal)"/> > > > > <nutrition:MealPanel id="pnlSnack2" meal="{nutritionData.snack2}" > > title="Snack : Please select one snack from below({maindata.snack2} > Cal Goal)"/> > > <!--mx:Button label="Create your own Dinner" > click="createDinner()"/--> > > > > <nutrition:MealPanel id="pnlDinner" meal="{nutritionData.dinner}" > > title="Dinner : Please select one meal from below({maindata.dinner} > Cal Goal)"/> > > > > <nutrition:MealPanel id="pnlSnack3" meal="{nutritionData.snack3}" > > title="Snack : Please select one snack from below({maindata.snack3} > Cal Goal)"/> > > </mx:VBox> > > > > > > </mx:HBox> > > </mx:Canvas> > > > > > > <mx:HBox width="100%" height="100%"> > > > > <mx:VBox width="30%" height="100%"> > > <mx:HBox> > > <mx:Label text="{'My Custom ' + plantype}"/> > > > > </mx:HBox> > > > > <mx:List id="ls" dataProvider="{customMeals}" width="100%"> > > <mx:itemRenderer> > > <mx:Component> > > <mx:VBox> > > <mx:Image width="100" height="100"/> > > <mx:Button label="Remove" click="dispatchEvent(new Event('removeMeal', > true))"/> > > <mx:Label text="{data.serving}"/> > > </mx:VBox> > > </mx:Component> > > </mx:itemRenderer> > > </mx:List> > > </mx:VBox> > > > > <mx:VBox width="100%" height="100%"> > > > > <!--mx:Label text="Please select ONE ITEM from list below"/--> > > <mx:ViewStack width="40%" height="410" borderStyle="inset" > borderThickness="2" id="vsCreateMeals"> > > > > <mx:VBox > > > <nutrition:Panelcreatemeal id="pnlCreateBreakfast" > meal="{nutritionData.breakfast}"/> > > </mx:VBox> > > > > <mx:VBox > > > <nutrition:Panelcreatemeal id="pnlCreateLunch" > meal="{nutritionData.lunch}"/> > > </mx:VBox> > > > > <mx:VBox > > > <nutrition:Panelcreatemeal id="pnlCreateDinner" > meal="{nutritionData.dinner}"/> > > </mx:VBox> > > > > </mx:ViewStack> > > <mx:HBox> > > <mx:Button label="Save" click="vsMain.selectedIndex = 0;"/> > > <mx:Button label="Cancel" click="vsMain.selectedIndex = 0;"/> > > </mx:HBox> > > > > </mx:VBox> > > > > > > </mx:HBox> > > > > </mx:ViewStack> > > > > </mx:Application> > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" > height="390" > > borderThicknessLeft="0" borderThicknessRight="0" > borderThicknessBottom="0" > > dropShadowEnabled="false" > > horizontalAlign="center" > xmlns:containers="com.dougmccune.containers.*" title="Select An Item > from below"> > > > > <mx:Script> > > <![CDATA[ > > //import com.createmealPanel; > > > > [Bindable] > > private var _meal:XMLList; > > > > public function set meal(value:XMLList):void > > { > > if(value) > > { > > _meal = value; > > createContainers(); > > } > > } > > > > private function createContainers():void > > { > > for each(var item:Object in _meal.itemdata) > > { > > if(item.available == "yes") > > { > > var mealitem:Panelcreatemealitem = new Panelcreatemealitem; > > coverflow.addChild(mealitem); > > mealitem.mealDetails = item; > > } > > } > > } > > ]]> > > </mx:Script> > > > > <containers:CoverFlowContainer id="coverflow" width="100%" > height="100%" > > horizontalGap="1" borderStyle="inset" backgroundColor="0xFFFFFF" > > segments="9" reflectionEnabled="true"/> > > > > <mx:HBox> > > <mx:Button label="item 1" > click="parentApplication.vsCreateMeals.selectedIndex=0;"/> > > <mx:Button label="side item 1" > click="parentApplication.vsCreateMeals.selectedIndex=1;"/> > > <mx:Button label="side item 2" > click="parentApplication.vsCreateMeals.selectedIndex=2;"/> > > </mx:HBox> > > </mx:Panel> > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="310" > height="320" > > title="{mealDetails.title}" horizontalAlign="center"> > > > > > > <mx:Metadata> > > [Event(name="addToMeal")] > > [Event(name="learnAboutThis")] > > </mx:Metadata> > > > > <mx:Script> > > <![CDATA[ > > import mx.controls.Alert; > > > > [Bindable] > > public var mealDetails:Object; > > > > > > private function calldispatch():void { > > parentApplication.createmeals_loadswf_var = mealDetails.swf; > > dispatchEvent(new Event('learnAboutThis', true)); > > > > } > > > > ]]> > > </mx:Script> > > > > <mx:Image source="{'/uploads/nutrition/' + mealDetails.imgsource }" > width="285" height="159"/> > > > > <mx:Label text="{mealDetails.serving}"/> > > > > <mx:Button label="Add to Meal" click="dispatchEvent(new > Event('addToMeal', true))"/> > > > > <mx:Button label="Learn About This" click="calldispatch()"/> > > > > </mx:Panel> > > > > > > > > --- In flexcoders@..., Sam Lai samuel.lai@ wrote: > > > > > > It seems like wherever this code is - > > > > > > [Bindable] > > > private var customMeals:ArrayCollection = new ArrayCollection; > > > > > > //throws error on this line > > > customMeals.addItem((event.target as mealitem).mealDetails); > > > > > > event.target is actually the panel containing the 'create meal item' > > > button, as opposed to the mealitem itself. Can you post some more of > > > the script and MXML for that part? > > > > > > The src folder is empty for me too in the ZIP file. > > > > > > 2009/7/2 Jason B nospam@: > > > > yes heres the results > > > > > "Main0.vsMain.HBox8.VBox968.vsCreateMeals.VBox971.pnlCreateBreakfast.cov\ > erflow.Panelcreatemealitem1006" > > > > > > > > How can I access the object data, it's in a file thats under the > folder /com/nutrition/file.mxml > > > > > > > > > > > > > > > > --- In flexcoders@..., Sam Lai <samuel.lai@> wrote: > > > >> > > > >> I'd add a trace statement just before it to see what type of > object > > > >> event.target is - it could be that the target is the UI > component, and > > > >> not the data object. > > > >> > > > >> //throws error on this line > > > >> trace(event.target); > > > >> customMeals.addItem((event.target as mealitem).mealDetails); > > > >> > > > >> 2009/7/2 Jason B <nospam@>: > > > >> > I've got an problem when the user clicks on button "Add to > Meal" it throws an error because it can't seem to reference the data in > mealDetails object inside the com/ directory? > > > >> > > > > >> > I'm trying to add the item to the list control. > > > >> > > > > >> > I have the code located here in case you want more details > > > >> > http://files.getdropbox.com/u/228472/mealsflex.zip > > > >> > > > > >> > > > > >> > [Bindable] > > > >> > private var customMeals:ArrayCollection = new ArrayCollection; > > > >> > > > > >> > //throws error on this line > > > >> > customMeals.addItem((event.target as mealitem).mealDetails); > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > <?xml version="1.0" encoding="utf-8"?> > > > >> > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="310" > height="320" > > > >> > title="{mealDetails.title}" horizontalAlign="center"> > > > >> > > > > >> > > > > >> > <mx:Metadata> > > > >> > [Event(name="addToMeal")] > > > >> > [Event(name="learnAboutThis")] > > > >> > </mx:Metadata> > > > >> > > > > >> > <mx:Script> > > > >> > <![CDATA[ > > > >> > import mx.controls.Alert; > > > >> > > > > >> > [Bindable] > > > >> > public var mealDetails:Object; > > > >> > > > > >> > > > > >> > private function calldispatch():void { > > > >> > > parentApplication.createmeals_loadswf_var = mealDetails.swf; > > > >> > dispatchEvent(new > Event('learnAboutThis', true)); > > > >> > > > > >> > } > > > >> > > > > >> > ]]> > > > >> > </mx:Script> > > > >> > > > > >> > <mx:Image source="{'/uploads/nutrition/' + > mealDetails.imgsource }" width="285" height="159"/> > > > >> > > > > >> > <mx:Label text="{mealDetails.serving}"/> > > > >> > > > > >> > <mx:Button label="Add to Meal" click="dispatchEvent(new > Event('addToMeal', true))"/> > > > >> > > > > >> > <mx:Button label="Learn About This" > click="calldispatch()"/> > > > >> > > > > >> > </mx:Panel> > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > ------------------------------------ > > > >> > > > > >> > -- > > > >> > Flexcoders Mailing List > > > >> > FAQ: > http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > > >> > Alternative FAQ location: > https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-\ > 1e62079f6847 > > > >> > Search Archives: > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups > Links > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > > > > > > > > > > > > > > > > > ------------------------------------ > > > > > > > > -- > > > > Flexcoders Mailing List > > > > FAQ: > http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > > > Alternative FAQ location: > https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-\ > 1e62079f6847 > > > > Search Archives: > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups > Links > > > > > > > > > > > > > > > > > > > > > > |
|
|
Re: getting the xml data from a dispatched eventimport com.nutrition.Panelcreatemealitem; -TH --- In flexcoders@..., "Jason B" <nospam@...> wrote: > > > It wont accept your suggestions > > Severity and Description Path Resource Location Creation Time Id > 1120: Access of undefined property Panelcreatemealitem. /src Main.mxml line 105 1246801954900 468962 > > > > > > > > > --- In flexcoders@..., "Tim Hoff" TimHoff@ wrote: > > > > > > Wow, I've got to say; "What a mess." However, you can get it to work > > with the following changes: > > > > [Bindable] > > private var customMeals:XMLListCollection = new XMLListCollection(); > > > > > > > > // addToMeal event Handler > > private function addToMealHandler(event:Event):void > > { > > customMeals.addItem((event.target as > > Panelcreatemealitem).mealDetails); > > Alert.show(customMeals.toString()); > > } > > > > You have some naming conflicts and, since you're dealing with xml, > > you'll need to use an XMLListCollection; instead of an > > > > -TH > > > > --- In flexcoders@..., "Jason B" <nospam@> wrote: > > > > > > Heres my three mxml files two of which are under the com/ folder and > > get imported...hope that helps > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > > layout="vertical" > > > creationComplete="init()" styleName="plain" > > xmlns:nutrition="com.nutrition.*" > > > paddingLeft="10" paddingTop="10" paddingRight="10" paddingBottom="10"> > > > > > > <mx:Script> > > > <![CDATA[ > > > import mx.collections.ArrayCollection; > > > import mx.collections.ICollectionView; > > > import mx.collections.XMLListCollection; > > > import com.nutrition.MealItem; > > > import mx.controls.Alert; > > > import mx.rpc.events.FaultEvent; > > > import mx.rpc.events.ResultEvent; > > > import mx.rpc.http.HTTPService; > > > // initialize > > > private function init():void > > > { > > > //load calories > > > httpservice_load("/main.php/flexnutrition/loadcalories", > > this["loadcaloriesResultHandler"]); > > > > > > hsNutrition.send(); > > > addEventListener('addToMeal', addToMealHandler); > > > addEventListener('removeMeal', removeMealHandler); > > > addEventListener('learnAboutThis', learnaboutthisswf); > > > > > > > > > > > > } > > > > > > private function httpservice_load(url_src:String, > > resulthandler:Function):void{ > > > > > > httpService.url = url_src; > > > > > > //var tmp:String = resulthandler.toString(); > > > //if(tmp != "none") > > > httpService.addEventListener(ResultEvent.RESULT, resulthandler); > > > httpService.send(); > > > } > > > > > > private function learnaboutthisswf(event:Event):void{ > > > vfc_guy.load("/uploads/swf/" + loadswf_var); > > > > > > } > > > > > > [Bindable] > > > private var nutritionData:XML; > > > [Bindable] > > > private var maindata:XML; > > > [Bindable] > > > public var loadswf_var:String; > > > [Bindable] > > > public var createmeals_loadswf_var:String; > > > > > > //load all calories for main meals > > > private function loadcaloriesResultHandler(event:ResultEvent):void > > > { > > > maindata = event.result as XML; > > > vfc_guy.load("/uploads/swf/" + maindata.swf); > > > } > > > > > > // nutrition result handler > > > private function nutritionResultHandler(event:ResultEvent):void > > > { > > > nutritionData = event.result as XML; > > > } > > > // nutrition fault handler > > > private function nutritionFaultHandler(event:FaultEvent):void > > > { > > > Alert.show(event.toString()); > > > } > > > > > > // create breakfast > > > private function createBreakfast():void > > > { > > > vsMain.selectedIndex = 1; > > > plantype = 'Breakfast'; > > > } > > > // create lunch > > > private function createLunch():void > > > { > > > vsMain.selectedIndex = 1; > > > plantype = 'Lunch'; > > > } > > > // create dinner > > > private function createDinner():void > > > { > > > vsMain.selectedIndex = 1; > > > plantype = 'Dinner'; > > > } > > > > > > [Bindable] > > > private var plantype:String; > > > > > > [Bindable] > > > private var customMeals:ArrayCollection = new ArrayCollection; > > > > > > // addToMeal event Handler > > > private function addToMealHandler(event:Event):void > > > { > > > trace(event.target); > > > //customMeals.addItem((event.target as mealitem).mealDetails); > > > Alert.show(event.toString()); > > > > > > } > > > > > > // removeMeal event Handler > > > private function removeMealHandler(event:Event):void > > > { > > > customMeals.removeItemAt(ls.selectedIndex); > > > } > > > > > > ]]> > > > </mx:Script> > > > > > > <mx:HTTPService id="hsNutrition" > > url="/main.php/flexnutrition/nutritioncal" > > > result="nutritionResultHandler(event)" > > > fault="nutritionFaultHandler(event)" resultFormat="e4x"/> > > > > > > <mx:HTTPService id="httpService" url="" resultFormat="e4x"/> > > > > > > <mx:Label id="totalcalories" text="{'Today\'s Meal Plan is based > > ' + maindata.totalcalories + ' Calorie Diet'}" fontWeight="bold" > > fontSize="18"/> > > > > > > <!--mx:Button label="Print Meal Menu" /--> > > > > > > <mx:ViewStack id="vsMain" width="100%" height="100%"> > > > > > > <mx:Canvas id="nutrition_canvas" width="100%" height="100%"> > > > > > > <mx:SWFLoader id="vfc_guy" source="" height="400" width="400" > > autoLoad="true" x="700" y="100" /> > > > > > > <mx:HBox width="100%" height="100%"> > > > > > > <mx:VBox width="40%" height="100%"> > > > > > > <nutrition:MealPanel id="pnlBreakfast" > > meal="{nutritionData.breakfast}" > > > title="Breakfast : Please select one meal from > > below({maindata.breakfast} Cal Goal)"/> > > > > > > <mx:HBox horizontalCenter="right"> > > > <mx:Button label="Create your own Breakfast" > > click="createBreakfast()"/> > > > </mx:HBox> > > > > > > > > > <nutrition:MealPanel id="pnlSnack1" meal="{nutritionData.snack1}" > > > title="Snack : Please select one snack from > > Cal Goal)"/> > > > <!--mx:Button label="Create your own Lunch" click="createLunch()"/--> > > > > > > <nutrition:MealPanel id="pnlLunch" meal="{nutritionData.lunch}" > > > title="Lunch : Please select one meal from below({maindata.lunch} Cal > > Goal)"/> > > > > > > <nutrition:MealPanel id="pnlSnack2" meal="{nutritionData.snack2}" > > > title="Snack : Please select one snack from below({maindata.snack2} > > Cal Goal)"/> > > > <!--mx:Button label="Create your own Dinner" > > click="createDinner()"/--> > > > > > > <nutrition:MealPanel id="pnlDinner" meal="{nutritionData.dinner}" > > > title="Dinner : Please select one meal from below({maindata.dinner} > > Cal Goal)"/> > > > > > > <nutrition:MealPanel id="pnlSnack3" meal="{nutritionData.snack3}" > > > title="Snack : Please select one snack from below({maindata.snack3} > > Cal Goal)"/> > > > </mx:VBox> > > > > > > > > > </mx:HBox> > > > </mx:Canvas> > > > > > > > > > <mx:HBox width="100%" height="100%"> > > > > > > <mx:VBox width="30%" height="100%"> > > > <mx:HBox> > > > <mx:Label text="{'My Custom ' + plantype}"/> > > > > > > </mx:HBox> > > > > > > <mx:List id="ls" dataProvider="{customMeals}" width="100%"> > > > <mx:itemRenderer> > > > <mx:Component> > > > <mx:VBox> > > > <mx:Image width="100" height="100"/> > > > <mx:Button label="Remove" click="dispatchEvent(new > > true))"/> > > > <mx:Label text="{data.serving}"/> > > > </mx:VBox> > > > </mx:Component> > > > </mx:itemRenderer> > > > </mx:List> > > > </mx:VBox> > > > > > > <mx:VBox width="100%" height="100%"> > > > > > > <!--mx:Label text="Please select ONE ITEM from list below"/--> > > > <mx:ViewStack width="40%" height="410" borderStyle="inset" > > borderThickness="2" id="vsCreateMeals"> > > > > > > <mx:VBox > > > > <nutrition:Panelcreatemeal id="pnlCreateBreakfast" > > meal="{nutritionData.breakfast}"/> > > > </mx:VBox> > > > > > > <mx:VBox > > > > <nutrition:Panelcreatemeal id="pnlCreateLunch" > > meal="{nutritionData.lunch}"/> > > > </mx:VBox> > > > > > > <mx:VBox > > > > <nutrition:Panelcreatemeal id="pnlCreateDinner" > > meal="{nutritionData.dinner}"/> > > > </mx:VBox> > > > > > > </mx:ViewStack> > > > <mx:HBox> > > > <mx:Button label="Save" click="vsMain.selectedIndex = 0;"/> > > > <mx:Button label="Cancel" click="vsMain.selectedIndex = 0;"/> > > > </mx:HBox> > > > > > > </mx:VBox> > > > > > > > > > </mx:HBox> > > > > > > </mx:ViewStack> > > > > > > </mx:Application> > > > > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" > > height="390" > > > borderThicknessLeft="0" borderThicknessRight="0" > > borderThicknessBottom="0" > > > dropShadowEnabled="false" > > > horizontalAlign="center" > > xmlns:containers="com.dougmccune.containers.*" title="Select An Item > > from below"> > > > > > > <mx:Script> > > > <![CDATA[ > > > //import com.createmealPanel; > > > > > > [Bindable] > > > private var _meal:XMLList; > > > > > > public function set meal(value:XMLList):void > > > { > > > if(value) > > > { > > > _meal = value; > > > createContainers(); > > > } > > > } > > > > > > private function createContainers():void > > > { > > > for each(var item:Object in _meal.itemdata) > > > { > > > if(item.available == "yes") > > > { > > > var mealitem:Panelcreatemealitem = new Panelcreatemealitem; > > > coverflow.addChild(mealitem); > > > mealitem.mealDetails = item; > > > } > > > } > > > } > > > ]]> > > > </mx:Script> > > > > > > <containers:CoverFlowContainer id="coverflow" width="100%" > > height="100%" > > > horizontalGap="1" borderStyle="inset" backgroundColor="0xFFFFFF" > > > segments="9" reflectionEnabled="true"/> > > > > > > <mx:HBox> > > > <mx:Button label="item 1" > > click="parentApplication.vsCreateMeals.selectedIndex=0;"/> > > > <mx:Button label="side item 1" > > click="parentApplication.vsCreateMeals.selectedIndex=1;"/> > > > <mx:Button label="side item 2" > > click="parentApplication.vsCreateMeals.selectedIndex=2;"/> > > > </mx:HBox> > > > </mx:Panel> > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="310" > > height="320" > > > title="{mealDetails.title}" horizontalAlign="center"> > > > > > > > > > <mx:Metadata> > > > [Event(name="addToMeal")] > > > [Event(name="learnAboutThis")] > > > </mx:Metadata> > > > > > > <mx:Script> > > > <![CDATA[ > > > import mx.controls.Alert; > > > > > > [Bindable] > > > public var mealDetails:Object; > > > > > > > > > private function calldispatch():void { > > > parentApplication.createmeals_loadswf_var = mealDetails.swf; > > > dispatchEvent(new Event('learnAboutThis', true)); > > > > > > } > > > > > > ]]> > > > </mx:Script> > > > > > > <mx:Image source="{'/uploads/nutrition/' + mealDetails.imgsource > > width="285" height="159"/> > > > > > > <mx:Label text="{mealDetails.serving}"/> > > > > > > <mx:Button label="Add to Meal" click="dispatchEvent(new > > Event('addToMeal', true))"/> > > > > > > <mx:Button label="Learn About This" click="calldispatch()"/> > > > > > > </mx:Panel> > > > > > > > > > > > > --- In flexcoders@..., Sam Lai samuel.lai@ wrote: > > > > > > > > It seems like wherever this code is - > > > > > > > > [Bindable] > > > > private var customMeals:ArrayCollection = new ArrayCollection; > > > > > > > > //throws error on this line > > > > customMeals.addItem((event.target as mealitem).mealDetails); > > > > > > > > event.target is actually the panel containing the 'create meal > > > > button, as opposed to the mealitem itself. Can you post some more of > > > > the script and MXML for that part? > > > > > > > > The src folder is empty for me too in the ZIP file. > > > > > > > > 2009/7/2 Jason B nospam@: > > > > > yes heres the results > > > > > > > "Main0.vsMain.HBox8.VBox968.vsCreateMeals.VBox971.pnlCreateBreakfast.cov\ \ > > erflow.Panelcreatemealitem1006" > > > > > > > > > > How can I access the object data, it's in a file thats under the > > folder /com/nutrition/file.mxml > > > > > > > > > > > > > > > > > > > > --- In flexcoders@..., Sam Lai <samuel.lai@> wrote: > > > > >> > > > > >> I'd add a trace statement just before it to see what type of > > object > > > > >> event.target is - it could be that the target is the UI > > component, and > > > > >> not the data object. > > > > >> > > > > >> //throws error on this line > > > > >> trace(event.target); > > > > >> customMeals.addItem((event.target as mealitem).mealDetails); > > > > >> > > > > >> 2009/7/2 Jason B <nospam@>: > > > > >> > I've got an problem when the user clicks on button "Add to > > Meal" it throws an error because it can't seem to reference the data > > mealDetails object inside the com/ directory? > > > > >> > > > > > >> > I'm trying to add the item to the list control. > > > > >> > > > > > >> > I have the code located here in case you want more details > > > > >> > http://files.getdropbox.com/u/228472/mealsflex.zip > > > > >> > > > > > >> > > > > > >> > [Bindable] > > > > >> > private var customMeals:ArrayCollection = new > > > > >> > > > > > >> > //throws error on this line > > > > >> > customMeals.addItem((event.target as mealitem).mealDetails); > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > <?xml version="1.0" encoding="utf-8"?> > > > > >> > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="310" > > height="320" > > > > >> > title="{mealDetails.title}" horizontalAlign="center"> > > > > >> > > > > > >> > > > > > >> > <mx:Metadata> > > > > >> > [Event(name="addToMeal")] > > > > >> > [Event(name="learnAboutThis")] > > > > >> > </mx:Metadata> > > > > >> > > > > > >> > <mx:Script> > > > > >> > <![CDATA[ > > > > >> > import mx.controls.Alert; > > > > >> > > > > > >> > [Bindable] > > > > >> > public var mealDetails:Object; > > > > >> > > > > > >> > > > > > >> > private function calldispatch():void { > > > > >> > > > parentApplication.createmeals_loadswf_var = mealDetails.swf; > > > > >> > dispatchEvent(new > > Event('learnAboutThis', true)); > > > > >> > > > > > >> > } > > > > >> > > > > > >> > ]]> > > > > >> > </mx:Script> > > > > >> > > > > > >> > <mx:Image source="{'/uploads/nutrition/' + > > mealDetails.imgsource }" width="285" height="159"/> > > > > >> > > > > > >> > <mx:Label text="{mealDetails.serving}"/> > > > > >> > > > > > >> > <mx:Button label="Add to Meal" click="dispatchEvent(new > > Event('addToMeal', true))"/> > > > > >> > > > > > >> > <mx:Button label="Learn About This" > > click="calldispatch()"/> > > > > >> > > > > > >> > </mx:Panel> > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > ------------------------------------ > > > > >> > > > > > >> > -- > > > > >> > Flexcoders Mailing List > > > > >> > FAQ: > > http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > > > >> > Alternative FAQ location: > > \ > > 1e62079f6847 > > > > >> > Search Archives: > > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups > > Links > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > > > > > > > > > > > > > > > > > > > > > ------------------------------------ > > > > > > > > > > -- > > > > > Flexcoders Mailing List > > > > > FAQ: > > http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > > > > Alternative FAQ location: > > \ > > 1e62079f6847 > > > > > Search Archives: > > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups > > Links > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
|
|
Re: getting the xml data from a dispatched eventI had that import in the main mxml before i replied to your message and still get an error?
--- In flexcoders@..., "Tim Hoff" <TimHoff@...> wrote: > > > import com.nutrition.Panelcreatemealitem; > > -TH > > --- In flexcoders@..., "Jason B" <nospam@> wrote: > > > > > > It wont accept your suggestions > > > > Severity and Description Path Resource Location Creation Time Id > > 1120: Access of undefined property Panelcreatemealitem. /src Main.mxml > line 105 1246801954900 468962 > > > > > > > > > > > > > > > > > > --- In flexcoders@..., "Tim Hoff" TimHoff@ wrote: > > > > > > > > > Wow, I've got to say; "What a mess." However, you can get it to work > > > with the following changes: > > > > > > [Bindable] > > > private var customMeals:XMLListCollection = new XMLListCollection(); > > > > > > > > > > > > // addToMeal event Handler > > > private function addToMealHandler(event:Event):void > > > { > > > customMeals.addItem((event.target as > > > Panelcreatemealitem).mealDetails); > > > Alert.show(customMeals.toString()); > > > } > > > > > > You have some naming conflicts and, since you're dealing with xml, > > > you'll need to use an XMLListCollection; instead of an > ArrayCollection. > > > > > > -TH > > > > > > --- In flexcoders@..., "Jason B" <nospam@> wrote: > > > > > > > > Heres my three mxml files two of which are under the com/ folder > and > > > get imported...hope that helps > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > > > layout="vertical" > > > > creationComplete="init()" styleName="plain" > > > xmlns:nutrition="com.nutrition.*" > > > > paddingLeft="10" paddingTop="10" paddingRight="10" > paddingBottom="10"> > > > > > > > > <mx:Script> > > > > <![CDATA[ > > > > import mx.collections.ArrayCollection; > > > > import mx.collections.ICollectionView; > > > > import mx.collections.XMLListCollection; > > > > import com.nutrition.MealItem; > > > > import mx.controls.Alert; > > > > import mx.rpc.events.FaultEvent; > > > > import mx.rpc.events.ResultEvent; > > > > import mx.rpc.http.HTTPService; > > > > // initialize > > > > private function init():void > > > > { > > > > //load calories > > > > httpservice_load("/main.php/flexnutrition/loadcalories", > > > this["loadcaloriesResultHandler"]); > > > > > > > > hsNutrition.send(); > > > > addEventListener('addToMeal', addToMealHandler); > > > > addEventListener('removeMeal', removeMealHandler); > > > > addEventListener('learnAboutThis', learnaboutthisswf); > > > > > > > > > > > > > > > > } > > > > > > > > private function httpservice_load(url_src:String, > > > resulthandler:Function):void{ > > > > > > > > httpService.url = url_src; > > > > > > > > //var tmp:String = resulthandler.toString(); > > > > //if(tmp != "none") > > > > httpService.addEventListener(ResultEvent.RESULT, resulthandler); > > > > httpService.send(); > > > > } > > > > > > > > private function learnaboutthisswf(event:Event):void{ > > > > vfc_guy.load("/uploads/swf/" + loadswf_var); > > > > > > > > } > > > > > > > > [Bindable] > > > > private var nutritionData:XML; > > > > [Bindable] > > > > private var maindata:XML; > > > > [Bindable] > > > > public var loadswf_var:String; > > > > [Bindable] > > > > public var createmeals_loadswf_var:String; > > > > > > > > //load all calories for main meals > > > > private function loadcaloriesResultHandler(event:ResultEvent):void > > > > { > > > > maindata = event.result as XML; > > > > vfc_guy.load("/uploads/swf/" + maindata.swf); > > > > } > > > > > > > > // nutrition result handler > > > > private function nutritionResultHandler(event:ResultEvent):void > > > > { > > > > nutritionData = event.result as XML; > > > > } > > > > // nutrition fault handler > > > > private function nutritionFaultHandler(event:FaultEvent):void > > > > { > > > > Alert.show(event.toString()); > > > > } > > > > > > > > // create breakfast > > > > private function createBreakfast():void > > > > { > > > > vsMain.selectedIndex = 1; > > > > plantype = 'Breakfast'; > > > > } > > > > // create lunch > > > > private function createLunch():void > > > > { > > > > vsMain.selectedIndex = 1; > > > > plantype = 'Lunch'; > > > > } > > > > // create dinner > > > > private function createDinner():void > > > > { > > > > vsMain.selectedIndex = 1; > > > > plantype = 'Dinner'; > > > > } > > > > > > > > [Bindable] > > > > private var plantype:String; > > > > > > > > [Bindable] > > > > private var customMeals:ArrayCollection = new ArrayCollection; > > > > > > > > // addToMeal event Handler > > > > private function addToMealHandler(event:Event):void > > > > { > > > > trace(event.target); > > > > //customMeals.addItem((event.target as mealitem).mealDetails); > > > > Alert.show(event.toString()); > > > > > > > > } > > > > > > > > // removeMeal event Handler > > > > private function removeMealHandler(event:Event):void > > > > { > > > > customMeals.removeItemAt(ls.selectedIndex); > > > > } > > > > > > > > ]]> > > > > </mx:Script> > > > > > > > > <mx:HTTPService id="hsNutrition" > > > url="/main.php/flexnutrition/nutritioncal" > > > > result="nutritionResultHandler(event)" > > > > fault="nutritionFaultHandler(event)" resultFormat="e4x"/> > > > > > > > > <mx:HTTPService id="httpService" url="" resultFormat="e4x"/> > > > > > > > > <mx:Label id="totalcalories" text="{'Today\'s Meal Plan is based > on a > > > ' + maindata.totalcalories + ' Calorie Diet'}" fontWeight="bold" > > > fontSize="18"/> > > > > > > > > <!--mx:Button label="Print Meal Menu" /--> > > > > > > > > <mx:ViewStack id="vsMain" width="100%" height="100%"> > > > > > > > > <mx:Canvas id="nutrition_canvas" width="100%" height="100%"> > > > > > > > > <mx:SWFLoader id="vfc_guy" source="" height="400" width="400" > > > autoLoad="true" x="700" y="100" /> > > > > > > > > <mx:HBox width="100%" height="100%"> > > > > > > > > <mx:VBox width="40%" height="100%"> > > > > > > > > <nutrition:MealPanel id="pnlBreakfast" > > > meal="{nutritionData.breakfast}" > > > > title="Breakfast : Please select one meal from > > > below({maindata.breakfast} Cal Goal)"/> > > > > > > > > <mx:HBox horizontalCenter="right"> > > > > <mx:Button label="Create your own Breakfast" > > > click="createBreakfast()"/> > > > > </mx:HBox> > > > > > > > > > > > > <nutrition:MealPanel id="pnlSnack1" meal="{nutritionData.snack1}" > > > > title="Snack : Please select one snack from > below({maindata.snack1} > > > Cal Goal)"/> > > > > <!--mx:Button label="Create your own Lunch" > click="createLunch()"/--> > > > > > > > > <nutrition:MealPanel id="pnlLunch" meal="{nutritionData.lunch}" > > > > title="Lunch : Please select one meal from below({maindata.lunch} > Cal > > > Goal)"/> > > > > > > > > <nutrition:MealPanel id="pnlSnack2" meal="{nutritionData.snack2}" > > > > title="Snack : Please select one snack from > below({maindata.snack2} > > > Cal Goal)"/> > > > > <!--mx:Button label="Create your own Dinner" > > > click="createDinner()"/--> > > > > > > > > <nutrition:MealPanel id="pnlDinner" meal="{nutritionData.dinner}" > > > > title="Dinner : Please select one meal from > below({maindata.dinner} > > > Cal Goal)"/> > > > > > > > > <nutrition:MealPanel id="pnlSnack3" meal="{nutritionData.snack3}" > > > > title="Snack : Please select one snack from > below({maindata.snack3} > > > Cal Goal)"/> > > > > </mx:VBox> > > > > > > > > > > > > </mx:HBox> > > > > </mx:Canvas> > > > > > > > > > > > > <mx:HBox width="100%" height="100%"> > > > > > > > > <mx:VBox width="30%" height="100%"> > > > > <mx:HBox> > > > > <mx:Label text="{'My Custom ' + plantype}"/> > > > > > > > > </mx:HBox> > > > > > > > > <mx:List id="ls" dataProvider="{customMeals}" width="100%"> > > > > <mx:itemRenderer> > > > > <mx:Component> > > > > <mx:VBox> > > > > <mx:Image width="100" height="100"/> > > > > <mx:Button label="Remove" click="dispatchEvent(new > Event('removeMeal', > > > true))"/> > > > > <mx:Label text="{data.serving}"/> > > > > </mx:VBox> > > > > </mx:Component> > > > > </mx:itemRenderer> > > > > </mx:List> > > > > </mx:VBox> > > > > > > > > <mx:VBox width="100%" height="100%"> > > > > > > > > <!--mx:Label text="Please select ONE ITEM from list below"/--> > > > > <mx:ViewStack width="40%" height="410" borderStyle="inset" > > > borderThickness="2" id="vsCreateMeals"> > > > > > > > > <mx:VBox > > > > > <nutrition:Panelcreatemeal id="pnlCreateBreakfast" > > > meal="{nutritionData.breakfast}"/> > > > > </mx:VBox> > > > > > > > > <mx:VBox > > > > > <nutrition:Panelcreatemeal id="pnlCreateLunch" > > > meal="{nutritionData.lunch}"/> > > > > </mx:VBox> > > > > > > > > <mx:VBox > > > > > <nutrition:Panelcreatemeal id="pnlCreateDinner" > > > meal="{nutritionData.dinner}"/> > > > > </mx:VBox> > > > > > > > > </mx:ViewStack> > > > > <mx:HBox> > > > > <mx:Button label="Save" click="vsMain.selectedIndex = 0;"/> > > > > <mx:Button label="Cancel" click="vsMain.selectedIndex = 0;"/> > > > > </mx:HBox> > > > > > > > > </mx:VBox> > > > > > > > > > > > > </mx:HBox> > > > > > > > > </mx:ViewStack> > > > > > > > > </mx:Application> > > > > > > > > > > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" > > > height="390" > > > > borderThicknessLeft="0" borderThicknessRight="0" > > > borderThicknessBottom="0" > > > > dropShadowEnabled="false" > > > > horizontalAlign="center" > > > xmlns:containers="com.dougmccune.containers.*" title="Select An Item > > > from below"> > > > > > > > > <mx:Script> > > > > <![CDATA[ > > > > //import com.createmealPanel; > > > > > > > > [Bindable] > > > > private var _meal:XMLList; > > > > > > > > public function set meal(value:XMLList):void > > > > { > > > > if(value) > > > > { > > > > _meal = value; > > > > createContainers(); > > > > } > > > > } > > > > > > > > private function createContainers():void > > > > { > > > > for each(var item:Object in _meal.itemdata) > > > > { > > > > if(item.available == "yes") > > > > { > > > > var mealitem:Panelcreatemealitem = new Panelcreatemealitem; > > > > coverflow.addChild(mealitem); > > > > mealitem.mealDetails = item; > > > > } > > > > } > > > > } > > > > ]]> > > > > </mx:Script> > > > > > > > > <containers:CoverFlowContainer id="coverflow" width="100%" > > > height="100%" > > > > horizontalGap="1" borderStyle="inset" backgroundColor="0xFFFFFF" > > > > segments="9" reflectionEnabled="true"/> > > > > > > > > <mx:HBox> > > > > <mx:Button label="item 1" > > > click="parentApplication.vsCreateMeals.selectedIndex=0;"/> > > > > <mx:Button label="side item 1" > > > click="parentApplication.vsCreateMeals.selectedIndex=1;"/> > > > > <mx:Button label="side item 2" > > > click="parentApplication.vsCreateMeals.selectedIndex=2;"/> > > > > </mx:HBox> > > > > </mx:Panel> > > > > > > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="310" > > > height="320" > > > > title="{mealDetails.title}" horizontalAlign="center"> > > > > > > > > > > > > <mx:Metadata> > > > > [Event(name="addToMeal")] > > > > [Event(name="learnAboutThis")] > > > > </mx:Metadata> > > > > > > > > <mx:Script> > > > > <![CDATA[ > > > > import mx.controls.Alert; > > > > > > > > [Bindable] > > > > public var mealDetails:Object; > > > > > > > > > > > > private function calldispatch():void { > > > > parentApplication.createmeals_loadswf_var = mealDetails.swf; > > > > dispatchEvent(new Event('learnAboutThis', true)); > > > > > > > > } > > > > > > > > ]]> > > > > </mx:Script> > > > > > > > > <mx:Image source="{'/uploads/nutrition/' + mealDetails.imgsource > }" > > > width="285" height="159"/> > > > > > > > > <mx:Label text="{mealDetails.serving}"/> > > > > > > > > <mx:Button label="Add to Meal" click="dispatchEvent(new > > > Event('addToMeal', true))"/> > > > > > > > > <mx:Button label="Learn About This" click="calldispatch()"/> > > > > > > > > </mx:Panel> > > > > > > > > > > > > > > > > --- In flexcoders@..., Sam Lai samuel.lai@ wrote: > > > > > > > > > > It seems like wherever this code is - > > > > > > > > > > [Bindable] > > > > > private var customMeals:ArrayCollection = new ArrayCollection; > > > > > > > > > > //throws error on this line > > > > > customMeals.addItem((event.target as mealitem).mealDetails); > > > > > > > > > > event.target is actually the panel containing the 'create meal > item' > > > > > button, as opposed to the mealitem itself. Can you post some > more of > > > > > the script and MXML for that part? > > > > > > > > > > The src folder is empty for me too in the ZIP file. > > > > > > > > > > 2009/7/2 Jason B nospam@: > > > > > > yes heres the results > > > > > > > > > > "Main0.vsMain.HBox8.VBox968.vsCreateMeals.VBox971.pnlCreateBreakfast.cov\ > \ > > > erflow.Panelcreatemealitem1006" > > > > > > > > > > > > How can I access the object data, it's in a file thats under > the > > > folder /com/nutrition/file.mxml > > > > > > > > > > > > > > > > > > > > > > > > --- In flexcoders@..., Sam Lai <samuel.lai@> > wrote: > > > > > >> > > > > > >> I'd add a trace statement just before it to see what type of > > > object > > > > > >> event.target is - it could be that the target is the UI > > > component, and > > > > > >> not the data object. > > > > > >> > > > > > >> //throws error on this line > > > > > >> trace(event.target); > > > > > >> customMeals.addItem((event.target as mealitem).mealDetails); > > > > > >> > > > > > >> 2009/7/2 Jason B <nospam@>: > > > > > >> > I've got an problem when the user clicks on button "Add to > > > Meal" it throws an error because it can't seem to reference the data > in > > > mealDetails object inside the com/ directory? > > > > > >> > > > > > > >> > I'm trying to add the item to the list control. > > > > > >> > > > > > > >> > I have the code located here in case you want more details > > > > > >> > http://files.getdropbox.com/u/228472/mealsflex.zip > > > > > >> > > > > > > >> > > > > > > >> > [Bindable] > > > > > >> > private var customMeals:ArrayCollection = new > ArrayCollection; > > > > > >> > > > > > > >> > //throws error on this line > > > > > >> > customMeals.addItem((event.target as > mealitem).mealDetails); > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > <?xml version="1.0" encoding="utf-8"?> > > > > > >> > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" > width="310" > > > height="320" > > > > > >> > title="{mealDetails.title}" horizontalAlign="center"> > > > > > >> > > > > > > >> > > > > > > >> > <mx:Metadata> > > > > > >> > [Event(name="addToMeal")] > > > > > >> > [Event(name="learnAboutThis")] > > > > > >> > </mx:Metadata> > > > > > >> > > > > > > >> > <mx:Script> > > > > > >> > <![CDATA[ > > > > > >> > import mx.controls.Alert; > > > > > >> > > > > > > >> > [Bindable] > > > > > >> > public var mealDetails:Object; > > > > > >> > > > > > > >> > > > > > > >> > private function calldispatch():void { > > > > > >> > > > > parentApplication.createmeals_loadswf_var = mealDetails.swf; > > > > > >> > dispatchEvent(new > > > Event('learnAboutThis', true)); > > > > > >> > > > > > > >> > } > > > > > >> > > > > > > >> > ]]> > > > > > >> > </mx:Script> > > > > > >> > > > > > > >> > <mx:Image source="{'/uploads/nutrition/' + > > > mealDetails.imgsource }" width="285" height="159"/> > > > > > >> > > > > > > >> > <mx:Label text="{mealDetails.serving}"/> > > > > > >> > > > > > > >> > <mx:Button label="Add to Meal" click="dispatchEvent(new > > > Event('addToMeal', true))"/> > > > > > >> > > > > > > >> > <mx:Button label="Learn About This" > > > click="calldispatch()"/> > > > > > >> > > > > > > >> > </mx:Panel> > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > ------------------------------------ > > > > > >> > > > > > > >> > -- > > > > > >> > Flexcoders Mailing List > > > > > >> > FAQ: > > > http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > > > > >> > Alternative FAQ location: > > > > https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-\ > \ > > > 1e62079f6847 > > > > > >> > Search Archives: > > > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! > Groups > > > Links > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ------------------------------------ > > > > > > > > > > > > -- > > > > > > Flexcoders Mailing List > > > > > > FAQ: > > > http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > > > > > Alternative FAQ location: > > > > https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-\ > \ > > > 1e62079f6847 > > > > > > Search Archives: > > > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! > Groups > > > Links > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
|
|
Re: getting the xml data from a dispatched eventHey Jason, When I created a new project with the code that you pasted, there were several bugs; including variable naming and component naming mis-matches, that had to be fixed; in order to even run the application. This is what happens when you just start with an idea and add on from there; instead of planning out the application first. Because of this, the code is all over the place. I might suggest taking a step backwards, and clean-up the code first. That will make it much easier to debug your issue. -TH --- In flexcoders@..., "Jason B" <nospam@...> wrote: > > I had that import in the main mxml before i replied to your message and still get an error? > > > > --- In flexcoders@..., "Tim Hoff" TimHoff@ wrote: > > > > > > import com.nutrition.Panelcreatemealitem; > > > > -TH > > > > --- In flexcoders@..., "Jason B" <nospam@> wrote: > > > > > > > > > It wont accept your suggestions > > > > > > Severity and Description Path Resource Location Creation Time Id > > > 1120: Access of undefined property Panelcreatemealitem. /src > > line 105 1246801954900 468962 > > > > > > > > > > > > > > > > > > > > > > > > > > > --- In flexcoders@..., "Tim Hoff" TimHoff@ wrote: > > > > > > > > > > > > Wow, I've got to say; "What a mess." However, you can get it to > > > > with the following changes: > > > > > > > > [Bindable] > > > > private var customMeals:XMLListCollection = new XMLListCollection(); > > > > > > > > > > > > > > > > // addToMeal event Handler > > > > private function addToMealHandler(event:Event):void > > > > { > > > > customMeals.addItem((event.target as > > > > Panelcreatemealitem).mealDetails); > > > > Alert.show(customMeals.toString()); > > > > } > > > > > > > > You have some naming conflicts and, since you're dealing with > > > > you'll need to use an XMLListCollection; instead of an > > ArrayCollection. > > > > > > > > -TH > > > > > > > > --- In flexcoders@..., "Jason B" <nospam@> wrote: > > > > > > > > > > Heres my three mxml files two of which are under the com/ folder > > and > > > > get imported...hope that helps > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > > > > layout="vertical" > > > > > creationComplete="init()" styleName="plain" > > > > xmlns:nutrition="com.nutrition.*" > > > > > paddingLeft="10" paddingTop="10" paddingRight="10" > > paddingBottom="10"> > > > > > > > > > > <mx:Script> > > > > > <![CDATA[ > > > > > import mx.collections.ArrayCollection; > > > > > import mx.collections.ICollectionView; > > > > > import mx.collections.XMLListCollection; > > > > > import com.nutrition.MealItem; > > > > > import mx.controls.Alert; > > > > > import mx.rpc.events.FaultEvent; > > > > > import mx.rpc.events.ResultEvent; > > > > > import mx.rpc.http.HTTPService; > > > > > // initialize > > > > > private function init():void > > > > > { > > > > > //load calories > > > > > httpservice_load("/main.php/flexnutrition/loadcalories", > > > > this["loadcaloriesResultHandler"]); > > > > > > > > > > hsNutrition.send(); > > > > > addEventListener('addToMeal', addToMealHandler); > > > > > addEventListener('removeMeal', removeMealHandler); > > > > > addEventListener('learnAboutThis', learnaboutthisswf); > > > > > > > > > > > > > > > > > > > > } > > > > > > > > > > private function httpservice_load(url_src:String, > > > > resulthandler:Function):void{ > > > > > > > > > > httpService.url = url_src; > > > > > > > > > > //var tmp:String = resulthandler.toString(); > > > > > //if(tmp != "none") > > > > > httpService.addEventListener(ResultEvent.RESULT, > > > > > httpService.send(); > > > > > } > > > > > > > > > > private function learnaboutthisswf(event:Event):void{ > > > > > vfc_guy.load("/uploads/swf/" + loadswf_var); > > > > > > > > > > } > > > > > > > > > > [Bindable] > > > > > private var nutritionData:XML; > > > > > [Bindable] > > > > > private var maindata:XML; > > > > > [Bindable] > > > > > public var loadswf_var:String; > > > > > [Bindable] > > > > > public var createmeals_loadswf_var:String; > > > > > > > > > > //load all calories for main meals > > > > > private function > > > > > { > > > > > maindata = event.result as XML; > > > > > vfc_guy.load("/uploads/swf/" + maindata.swf); > > > > > } > > > > > > > > > > // nutrition result handler > > > > > private function nutritionResultHandler(event:ResultEvent):void > > > > > { > > > > > nutritionData = event.result as XML; > > > > > } > > > > > // nutrition fault handler > > > > > private function nutritionFaultHandler(event:FaultEvent):void > > > > > { > > > > > Alert.show(event.toString()); > > > > > } > > > > > > > > > > // create breakfast > > > > > private function createBreakfast():void > > > > > { > > > > > vsMain.selectedIndex = 1; > > > > > plantype = 'Breakfast'; > > > > > } > > > > > // create lunch > > > > > private function createLunch():void > > > > > { > > > > > vsMain.selectedIndex = 1; > > > > > plantype = 'Lunch'; > > > > > } > > > > > // create dinner > > > > > private function createDinner():void > > > > > { > > > > > vsMain.selectedIndex = 1; > > > > > plantype = 'Dinner'; > > > > > } > > > > > > > > > > [Bindable] > > > > > private var plantype:String; > > > > > > > > > > [Bindable] > > > > > private var customMeals:ArrayCollection = new ArrayCollection; > > > > > > > > > > // addToMeal event Handler > > > > > private function addToMealHandler(event:Event):void > > > > > { > > > > > trace(event.target); > > > > > //customMeals.addItem((event.target as mealitem).mealDetails); > > > > > Alert.show(event.toString()); > > > > > > > > > > } > > > > > > > > > > // removeMeal event Handler > > > > > private function removeMealHandler(event:Event):void > > > > > { > > > > > customMeals.removeItemAt(ls.selectedIndex); > > > > > } > > > > > > > > > > ]]> > > > > > </mx:Script> > > > > > > > > > > <mx:HTTPService id="hsNutrition" > > > > url="/main.php/flexnutrition/nutritioncal" > > > > > result="nutritionResultHandler(event)" > > > > > fault="nutritionFaultHandler(event)" resultFormat="e4x"/> > > > > > > > > > > <mx:HTTPService id="httpService" url="" resultFormat="e4x"/> > > > > > > > > > > <mx:Label id="totalcalories" text="{'Today\'s Meal Plan is > > on a > > > > ' + maindata.totalcalories + ' Calorie Diet'}" fontWeight="bold" > > > > fontSize="18"/> > > > > > > > > > > <!--mx:Button label="Print Meal Menu" /--> > > > > > > > > > > <mx:ViewStack id="vsMain" width="100%" height="100%"> > > > > > > > > > > <mx:Canvas id="nutrition_canvas" width="100%" height="100%"> > > > > > > > > > > <mx:SWFLoader id="vfc_guy" source="" height="400" width="400" > > > > autoLoad="true" x="700" y="100" /> > > > > > > > > > > <mx:HBox width="100%" height="100%"> > > > > > > > > > > <mx:VBox width="40%" height="100%"> > > > > > > > > > > <nutrition:MealPanel id="pnlBreakfast" > > > > meal="{nutritionData.breakfast}" > > > > > title="Breakfast : Please select one meal from > > > > below({maindata.breakfast} Cal Goal)"/> > > > > > > > > > > <mx:HBox horizontalCenter="right"> > > > > > <mx:Button label="Create your own Breakfast" > > > > click="createBreakfast()"/> > > > > > </mx:HBox> > > > > > > > > > > > > > > > <nutrition:MealPanel id="pnlSnack1" > > > > > title="Snack : Please select one snack from > > below({maindata.snack1} > > > > Cal Goal)"/> > > > > > <!--mx:Button label="Create your own Lunch" > > click="createLunch()"/--> > > > > > > > > > > <nutrition:MealPanel id="pnlLunch" meal="{nutritionData.lunch}" > > > > > title="Lunch : Please select one meal from below({maindata.lunch} > > Cal > > > > Goal)"/> > > > > > > > > > > <nutrition:MealPanel id="pnlSnack2" meal="{nutritionData.snack2}" > > > > > title="Snack : Please select one snack from > > below({maindata.snack2} > > > > Cal Goal)"/> > > > > > <!--mx:Button label="Create your own Dinner" > > > > click="createDinner()"/--> > > > > > > > > > > <nutrition:MealPanel id="pnlDinner" meal="{nutritionData.dinner}" > > > > > title="Dinner : Please select one meal from > > below({maindata.dinner} > > > > Cal Goal)"/> > > > > > > > > > > <nutrition:MealPanel id="pnlSnack3" meal="{nutritionData.snack3}" > > > > > title="Snack : Please select one snack from > > below({maindata.snack3} > > > > Cal Goal)"/> > > > > > </mx:VBox> > > > > > > > > > > > > > > > </mx:HBox> > > > > > </mx:Canvas> > > > > > > > > > > > > > > > <mx:HBox width="100%" height="100%"> > > > > > > > > > > <mx:VBox width="30%" height="100%"> > > > > > <mx:HBox> > > > > > <mx:Label text="{'My Custom ' + plantype}"/> > > > > > > > > > > </mx:HBox> > > > > > > > > > > <mx:List id="ls" dataProvider="{customMeals}" width="100%"> > > > > > <mx:itemRenderer> > > > > > <mx:Component> > > > > > <mx:VBox> > > > > > <mx:Image width="100" height="100"/> > > > > > <mx:Button label="Remove" click="dispatchEvent(new > > Event('removeMeal', > > > > true))"/> > > > > > <mx:Label text="{data.serving}"/> > > > > > </mx:VBox> > > > > > </mx:Component> > > > > > </mx:itemRenderer> > > > > > </mx:List> > > > > > </mx:VBox> > > > > > > > > > > <mx:VBox width="100%" height="100%"> > > > > > > > > > > <!--mx:Label text="Please select ONE ITEM from list below"/--> > > > > > <mx:ViewStack width="40%" height="410" borderStyle="inset" > > > > borderThickness="2" id="vsCreateMeals"> > > > > > > > > > > <mx:VBox > > > > > > <nutrition:Panelcreatemeal id="pnlCreateBreakfast" > > > > meal="{nutritionData.breakfast}"/> > > > > > </mx:VBox> > > > > > > > > > > <mx:VBox > > > > > > <nutrition:Panelcreatemeal id="pnlCreateLunch" > > > > meal="{nutritionData.lunch}"/> > > > > > </mx:VBox> > > > > > > > > > > <mx:VBox > > > > > > <nutrition:Panelcreatemeal id="pnlCreateDinner" > > > > meal="{nutritionData.dinner}"/> > > > > > </mx:VBox> > > > > > > > > > > </mx:ViewStack> > > > > > <mx:HBox> > > > > > <mx:Button label="Save" click="vsMain.selectedIndex = 0;"/> > > > > > <mx:Button label="Cancel" click="vsMain.selectedIndex = 0;"/> > > > > > </mx:HBox> > > > > > > > > > > </mx:VBox> > > > > > > > > > > > > > > > </mx:HBox> > > > > > > > > > > </mx:ViewStack> > > > > > > > > > > </mx:Application> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" > > > > height="390" > > > > > borderThicknessLeft="0" borderThicknessRight="0" > > > > borderThicknessBottom="0" > > > > > dropShadowEnabled="false" > > > > > horizontalAlign="center" > > > > xmlns:containers="com.dougmccune.containers.*" title="Select An Item > > > > from below"> > > > > > > > > > > <mx:Script> > > > > > <![CDATA[ > > > > > //import com.createmealPanel; > > > > > > > > > > [Bindable] > > > > > private var _meal:XMLList; > > > > > > > > > > public function set meal(value:XMLList):void > > > > > { > > > > > if(value) > > > > > { > > > > > _meal = value; > > > > > createContainers(); > > > > > } > > > > > } > > > > > > > > > > private function createContainers():void > > > > > { > > > > > for each(var item:Object in _meal.itemdata) > > > > > { > > > > > if(item.available == "yes") > > > > > { > > > > > var mealitem:Panelcreatemealitem = new Panelcreatemealitem; > > > > > coverflow.addChild(mealitem); > > > > > mealitem.mealDetails = item; > > > > > } > > > > > } > > > > > } > > > > > ]]> > > > > > </mx:Script> > > > > > > > > > > <containers:CoverFlowContainer id="coverflow" width="100%" > > > > height="100%" > > > > > horizontalGap="1" borderStyle="inset" > > > > > segments="9" reflectionEnabled="true"/> > > > > > > > > > > <mx:HBox> > > > > > <mx:Button label="item 1" > > > > click="parentApplication.vsCreateMeals.selectedIndex=0;"/> > > > > > <mx:Button label="side item 1" > > > > click="parentApplication.vsCreateMeals.selectedIndex=1;"/> > > > > > <mx:Button label="side item 2" > > > > click="parentApplication.vsCreateMeals.selectedIndex=2;"/> > > > > > </mx:HBox> > > > > > </mx:Panel> > > > > > > > > > > > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" > > > > height="320" > > > > > title="{mealDetails.title}" horizontalAlign="center"> > > > > > > > > > > > > > > > <mx:Metadata> > > > > > [Event(name="addToMeal")] > > > > > [Event(name="learnAboutThis")] > > > > > </mx:Metadata> > > > > > > > > > > <mx:Script> > > > > > <![CDATA[ > > > > > import mx.controls.Alert; > > > > > > > > > > [Bindable] > > > > > public var mealDetails:Object; > > > > > > > > > > > > > > > private function calldispatch():void { > > > > > parentApplication.createmeals_loadswf_var = mealDetails.swf; > > > > > dispatchEvent(new Event('learnAboutThis', true)); > > > > > > > > > > } > > > > > > > > > > ]]> > > > > > </mx:Script> > > > > > > > > > > <mx:Image source="{'/uploads/nutrition/' + > > }" > > > > width="285" height="159"/> > > > > > > > > > > <mx:Label text="{mealDetails.serving}"/> > > > > > > > > > > <mx:Button label="Add to Meal" click="dispatchEvent(new > > > > Event('addToMeal', true))"/> > > > > > > > > > > <mx:Button label="Learn About This" click="calldispatch()"/> > > > > > > > > > > </mx:Panel> > > > > > > > > > > > > > > > > > > > > --- In flexcoders@..., Sam Lai samuel.lai@ wrote: > > > > > > > > > > > > It seems like wherever this code is - > > > > > > > > > > > > [Bindable] > > > > > > private var customMeals:ArrayCollection = new > > > > > > > > > > > > //throws error on this line > > > > > > customMeals.addItem((event.target as mealitem).mealDetails); > > > > > > > > > > > > event.target is actually the panel containing the 'create meal > > item' > > > > > > button, as opposed to the mealitem itself. Can you post some > > more of > > > > > > the script and MXML for that part? > > > > > > > > > > > > The src folder is empty for me too in the ZIP file. > > > > > > > > > > > > 2009/7/2 Jason B nospam@: > > > > > > > yes heres the results > > > > > > > > > > > > > \ > > \ > > > > erflow.Panelcreatemealitem1006" > > > > > > > > > > > > > > How can I access the object data, it's in a file thats under > > the > > > > folder /com/nutrition/file.mxml > > > > > > > > > > > > > > > > > > > > > > > > > > > > --- In flexcoders@..., Sam Lai <samuel.lai@> > > wrote: > > > > > > >> > > > > > > >> I'd add a trace statement just before it to see what type of > > > > object > > > > > > >> event.target is - it could be that the target is the UI > > > > component, and > > > > > > >> not the data object. > > > > > > >> > > > > > > >> //throws error on this line > > > > > > >> trace(event.target); > > > > > > >> customMeals.addItem((event.target as mealitem).mealDetails); > > > > > > >> > > > > > > >> 2009/7/2 Jason B <nospam@>: > > > > > > >> > I've got an problem when the user clicks on button "Add to > > > > Meal" it throws an error because it can't seem to reference the data > > in > > > > mealDetails object inside the com/ directory? > > > > > > >> > > > > > > > >> > I'm trying to add the item to the list control. > > > > > > >> > > > > > > > >> > I have the code located here in case you want more details > > > > > > >> > http://files.getdropbox.com/u/228472/mealsflex.zip > > > > > > >> > > > > > > > >> > > > > > > > >> > [Bindable] > > > > > > >> > private var customMeals:ArrayCollection = new > > ArrayCollection; > > > > > > >> > > > > > > > >> > //throws error on this line > > > > > > >> > customMeals.addItem((event.target as > > mealitem).mealDetails); > > > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > > >> > <?xml version="1.0" encoding="utf-8"?> > > > > > > >> > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" > > width="310" > > > > height="320" > > > > > > >> > title="{mealDetails.title}" horizontalAlign="center"> > > > > > > >> > > > > > > > >> > > > > > > > >> > <mx:Metadata> > > > > > > >> > [Event(name="addToMeal")] > > > > > > >> > [Event(name="learnAboutThis")] > > > > > > >> > </mx:Metadata> > > > > > > >> > > > > > > > >> > <mx:Script> > > > > > > >> > <![CDATA[ > > > > > > >> > import mx.controls.Alert; > > > > > > >> > > > > > > > >> > [Bindable] > > > > > > >> > public var mealDetails:Object; > > > > > > >> > > > > > > > >> > > > > > > > >> > private function calldispatch():void { > > > > > > >> > > > > > parentApplication.createmeals_loadswf_var = mealDetails.swf; > > > > > > >> > dispatchEvent(new > > > > Event('learnAboutThis', true)); > > > > > > >> > > > > > > > >> > } > > > > > > >> > > > > > > > >> > ]]> > > > > > > >> > </mx:Script> > > > > > > >> > > > > > > > >> > <mx:Image source="{'/uploads/nutrition/' + > > > > mealDetails.imgsource }" width="285" height="159"/> > > > > > > >> > > > > > > > >> > <mx:Label text="{mealDetails.serving}"/> > > > > > > >> > > > > > > > >> > <mx:Button label="Add to Meal" click="dispatchEvent(new > > > > Event('addToMeal', true))"/> > > > > > > >> > > > > > > > >> > <mx:Button label="Learn About This" > > > > click="calldispatch()"/> > > > > > > >> > > > > > > > >> > </mx:Panel> > > > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > > >> > ------------------------------------ > > > > > > >> > > > > > > > >> > -- > > > > > > >> > Flexcoders Mailing List > > > > > > >> > FAQ: > > > > http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > > > > > >> > Alternative FAQ location: > > > > > > \ > > \ > > > > 1e62079f6847 > > > > > > >> > Search Archives: > > > > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! > > Groups > > > > Links > > > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ------------------------------------ > > > > > > > > > > > > > > -- > > > > > > > Flexcoders Mailing List > > > > > > > FAQ: > > > > http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > > > > > > Alternative FAQ location: > > > > > > \ > > \ > > > > 1e62079f6847 > > > > > > > Search Archives: > > > > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! > > Groups > > > > Links > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
|
|
Re: getting the xml data from a dispatched eventfunny you mention that since I paid an experienced Flex Engineer to build this yet I'm stuck debugging it.
I'll see what I can do, guess it's time to learn, It's disappointing to hear it was built wrong. --- In flexcoders@..., "Tim Hoff" <TimHoff@...> wrote: > > > Hey Jason, > > When I created a new project with the code that you pasted, there were > several bugs; including variable naming and component naming > mis-matches, that had to be fixed; in order to even run the application. > This is what happens when you just start with an idea and add on from > there; instead of planning out the application first. Because of this, > the code is all over the place. I might suggest taking a step > backwards, and clean-up the code first. That will make it much easier > to debug your issue. > > -TH > > --- In flexcoders@..., "Jason B" <nospam@> wrote: > > > > I had that import in the main mxml before i replied to your message > and still get an error? > > > > > > > > --- In flexcoders@..., "Tim Hoff" TimHoff@ wrote: > > > > > > > > > import com.nutrition.Panelcreatemealitem; > > > > > > -TH > > > > > > --- In flexcoders@..., "Jason B" <nospam@> wrote: > > > > > > > > > > > > It wont accept your suggestions > > > > > > > > Severity and Description Path Resource Location Creation Time Id > > > > 1120: Access of undefined property Panelcreatemealitem. /src > Main.mxml > > > line 105 1246801954900 468962 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --- In flexcoders@..., "Tim Hoff" TimHoff@ wrote: > > > > > > > > > > > > > > > Wow, I've got to say; "What a mess." However, you can get it to > work > > > > > with the following changes: > > > > > > > > > > [Bindable] > > > > > private var customMeals:XMLListCollection = new > XMLListCollection(); > > > > > > > > > > > > > > > > > > > > // addToMeal event Handler > > > > > private function addToMealHandler(event:Event):void > > > > > { > > > > > customMeals.addItem((event.target as > > > > > Panelcreatemealitem).mealDetails); > > > > > Alert.show(customMeals.toString()); > > > > > } > > > > > > > > > > You have some naming conflicts and, since you're dealing with > xml, > > > > > you'll need to use an XMLListCollection; instead of an > > > ArrayCollection. > > > > > > > > > > -TH > > > > > > > > > > --- In flexcoders@..., "Jason B" <nospam@> wrote: > > > > > > > > > > > > Heres my three mxml files two of which are under the com/ > folder > > > and > > > > > get imported...hope that helps > > > > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > > > > > layout="vertical" > > > > > > creationComplete="init()" styleName="plain" > > > > > xmlns:nutrition="com.nutrition.*" > > > > > > paddingLeft="10" paddingTop="10" paddingRight="10" > > > paddingBottom="10"> > > > > > > > > > > > > <mx:Script> > > > > > > <![CDATA[ > > > > > > import mx.collections.ArrayCollection; > > > > > > import mx.collections.ICollectionView; > > > > > > import mx.collections.XMLListCollection; > > > > > > import com.nutrition.MealItem; > > > > > > import mx.controls.Alert; > > > > > > import mx.rpc.events.FaultEvent; > > > > > > import mx.rpc.events.ResultEvent; > > > > > > import mx.rpc.http.HTTPService; > > > > > > // initialize > > > > > > private function init():void > > > > > > { > > > > > > //load calories > > > > > > httpservice_load("/main.php/flexnutrition/loadcalories", > > > > > this["loadcaloriesResultHandler"]); > > > > > > > > > > > > hsNutrition.send(); > > > > > > addEventListener('addToMeal', addToMealHandler); > > > > > > addEventListener('removeMeal', removeMealHandler); > > > > > > addEventListener('learnAboutThis', learnaboutthisswf); > > > > > > > > > > > > > > > > > > > > > > > > } > > > > > > > > > > > > private function httpservice_load(url_src:String, > > > > > resulthandler:Function):void{ > > > > > > > > > > > > httpService.url = url_src; > > > > > > > > > > > > //var tmp:String = resulthandler.toString(); > > > > > > //if(tmp != "none") > > > > > > httpService.addEventListener(ResultEvent.RESULT, > resulthandler); > > > > > > httpService.send(); > > > > > > } > > > > > > > > > > > > private function learnaboutthisswf(event:Event):void{ > > > > > > vfc_guy.load("/uploads/swf/" + loadswf_var); > > > > > > > > > > > > } > > > > > > > > > > > > [Bindable] > > > > > > private var nutritionData:XML; > > > > > > [Bindable] > > > > > > private var maindata:XML; > > > > > > [Bindable] > > > > > > public var loadswf_var:String; > > > > > > [Bindable] > > > > > > public var createmeals_loadswf_var:String; > > > > > > > > > > > > //load all calories for main meals > > > > > > private function > loadcaloriesResultHandler(event:ResultEvent):void > > > > > > { > > > > > > maindata = event.result as XML; > > > > > > vfc_guy.load("/uploads/swf/" + maindata.swf); > > > > > > } > > > > > > > > > > > > // nutrition result handler > > > > > > private function > nutritionResultHandler(event:ResultEvent):void > > > > > > { > > > > > > nutritionData = event.result as XML; > > > > > > } > > > > > > // nutrition fault handler > > > > > > private function nutritionFaultHandler(event:FaultEvent):void > > > > > > { > > > > > > Alert.show(event.toString()); > > > > > > } > > > > > > > > > > > > // create breakfast > > > > > > private function createBreakfast():void > > > > > > { > > > > > > vsMain.selectedIndex = 1; > > > > > > plantype = 'Breakfast'; > > > > > > } > > > > > > // create lunch > > > > > > private function createLunch():void > > > > > > { > > > > > > vsMain.selectedIndex = 1; > > > > > > plantype = 'Lunch'; > > > > > > } > > > > > > // create dinner > > > > > > private function createDinner():void > > > > > > { > > > > > > vsMain.selectedIndex = 1; > > > > > > plantype = 'Dinner'; > > > > > > } > > > > > > > > > > > > [Bindable] > > > > > > private var plantype:String; > > > > > > > > > > > > [Bindable] > > > > > > private var customMeals:ArrayCollection = new ArrayCollection; > > > > > > > > > > > > // addToMeal event Handler > > > > > > private function addToMealHandler(event:Event):void > > > > > > { > > > > > > trace(event.target); > > > > > > //customMeals.addItem((event.target as mealitem).mealDetails); > > > > > > Alert.show(event.toString()); > > > > > > > > > > > > } > > > > > > > > > > > > // removeMeal event Handler > > > > > > private function removeMealHandler(event:Event):void > > > > > > { > > > > > > customMeals.removeItemAt(ls.selectedIndex); > > > > > > } > > > > > > > > > > > > ]]> > > > > > > </mx:Script> > > > > > > > > > > > > <mx:HTTPService id="hsNutrition" > > > > > url="/main.php/flexnutrition/nutritioncal" > > > > > > result="nutritionResultHandler(event)" > > > > > > fault="nutritionFaultHandler(event)" resultFormat="e4x"/> > > > > > > > > > > > > <mx:HTTPService id="httpService" url="" resultFormat="e4x"/> > > > > > > > > > > > > <mx:Label id="totalcalories" text="{'Today\'s Meal Plan is > based > > > on a > > > > > ' + maindata.totalcalories + ' Calorie Diet'}" fontWeight="bold" > > > > > fontSize="18"/> > > > > > > > > > > > > <!--mx:Button label="Print Meal Menu" /--> > > > > > > > > > > > > <mx:ViewStack id="vsMain" width="100%" height="100%"> > > > > > > > > > > > > <mx:Canvas id="nutrition_canvas" width="100%" height="100%"> > > > > > > > > > > > > <mx:SWFLoader id="vfc_guy" source="" height="400" width="400" > > > > > autoLoad="true" x="700" y="100" /> > > > > > > > > > > > > <mx:HBox width="100%" height="100%"> > > > > > > > > > > > > <mx:VBox width="40%" height="100%"> > > > > > > > > > > > > <nutrition:MealPanel id="pnlBreakfast" > > > > > meal="{nutritionData.breakfast}" > > > > > > title="Breakfast : Please select one meal from > > > > > below({maindata.breakfast} Cal Goal)"/> > > > > > > > > > > > > <mx:HBox horizontalCenter="right"> > > > > > > <mx:Button label="Create your own Breakfast" > > > > > click="createBreakfast()"/> > > > > > > </mx:HBox> > > > > > > > > > > > > > > > > > > <nutrition:MealPanel id="pnlSnack1" > meal="{nutritionData.snack1}" > > > > > > title="Snack : Please select one snack from > > > below({maindata.snack1} > > > > > Cal Goal)"/> > > > > > > <!--mx:Button label="Create your own Lunch" > > > click="createLunch()"/--> > > > > > > > > > > > > <nutrition:MealPanel id="pnlLunch" > meal="{nutritionData.lunch}" > > > > > > title="Lunch : Please select one meal from > below({maindata.lunch} > > > Cal > > > > > Goal)"/> > > > > > > > > > > > > <nutrition:MealPanel id="pnlSnack2" > meal="{nutritionData.snack2}" > > > > > > title="Snack : Please select one snack from > > > below({maindata.snack2} > > > > > Cal Goal)"/> > > > > > > <!--mx:Button label="Create your own Dinner" > > > > > click="createDinner()"/--> > > > > > > > > > > > > <nutrition:MealPanel id="pnlDinner" > meal="{nutritionData.dinner}" > > > > > > title="Dinner : Please select one meal from > > > below({maindata.dinner} > > > > > Cal Goal)"/> > > > > > > > > > > > > <nutrition:MealPanel id="pnlSnack3" > meal="{nutritionData.snack3}" > > > > > > title="Snack : Please select one snack from > > > below({maindata.snack3} > > > > > Cal Goal)"/> > > > > > > </mx:VBox> > > > > > > > > > > > > > > > > > > </mx:HBox> > > > > > > </mx:Canvas> > > > > > > > > > > > > > > > > > > <mx:HBox width="100%" height="100%"> > > > > > > > > > > > > <mx:VBox width="30%" height="100%"> > > > > > > <mx:HBox> > > > > > > <mx:Label text="{'My Custom ' + plantype}"/> > > > > > > > > > > > > </mx:HBox> > > > > > > > > > > > > <mx:List id="ls" dataProvider="{customMeals}" width="100%"> > > > > > > <mx:itemRenderer> > > > > > > <mx:Component> > > > > > > <mx:VBox> > > > > > > <mx:Image width="100" height="100"/> > > > > > > <mx:Button label="Remove" click="dispatchEvent(new > > > Event('removeMeal', > > > > > true))"/> > > > > > > <mx:Label text="{data.serving}"/> > > > > > > </mx:VBox> > > > > > > </mx:Component> > > > > > > </mx:itemRenderer> > > > > > > </mx:List> > > > > > > </mx:VBox> > > > > > > > > > > > > <mx:VBox width="100%" height="100%"> > > > > > > > > > > > > <!--mx:Label text="Please select ONE ITEM from list below"/--> > > > > > > <mx:ViewStack width="40%" height="410" borderStyle="inset" > > > > > borderThickness="2" id="vsCreateMeals"> > > > > > > > > > > > > <mx:VBox > > > > > > > <nutrition:Panelcreatemeal id="pnlCreateBreakfast" > > > > > meal="{nutritionData.breakfast}"/> > > > > > > </mx:VBox> > > > > > > > > > > > > <mx:VBox > > > > > > > <nutrition:Panelcreatemeal id="pnlCreateLunch" > > > > > meal="{nutritionData.lunch}"/> > > > > > > </mx:VBox> > > > > > > > > > > > > <mx:VBox > > > > > > > <nutrition:Panelcreatemeal id="pnlCreateDinner" > > > > > meal="{nutritionData.dinner}"/> > > > > > > </mx:VBox> > > > > > > > > > > > > </mx:ViewStack> > > > > > > <mx:HBox> > > > > > > <mx:Button label="Save" click="vsMain.selectedIndex = 0;"/> > > > > > > <mx:Button label="Cancel" click="vsMain.selectedIndex = 0;"/> > > > > > > </mx:HBox> > > > > > > > > > > > > </mx:VBox> > > > > > > > > > > > > > > > > > > </mx:HBox> > > > > > > > > > > > > </mx:ViewStack> > > > > > > > > > > > > </mx:Application> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" > width="100%" > > > > > height="390" > > > > > > borderThicknessLeft="0" borderThicknessRight="0" > > > > > borderThicknessBottom="0" > > > > > > dropShadowEnabled="false" > > > > > > horizontalAlign="center" > > > > > xmlns:containers="com.dougmccune.containers.*" title="Select An > Item > > > > > from below"> > > > > > > > > > > > > <mx:Script> > > > > > > <![CDATA[ > > > > > > //import com.createmealPanel; > > > > > > > > > > > > [Bindable] > > > > > > private var _meal:XMLList; > > > > > > > > > > > > public function set meal(value:XMLList):void > > > > > > { > > > > > > if(value) > > > > > > { > > > > > > _meal = value; > > > > > > createContainers(); > > > > > > } > > > > > > } > > > > > > > > > > > > private function createContainers():void > > > > > > { > > > > > > for each(var item:Object in _meal.itemdata) > > > > > > { > > > > > > if(item.available == "yes") > > > > > > { > > > > > > var mealitem:Panelcreatemealitem = new Panelcreatemealitem; > > > > > > coverflow.addChild(mealitem); > > > > > > mealitem.mealDetails = item; > > > > > > } > > > > > > } > > > > > > } > > > > > > ]]> > > > > > > </mx:Script> > > > > > > > > > > > > <containers:CoverFlowContainer id="coverflow" width="100%" > > > > > height="100%" > > > > > > horizontalGap="1" borderStyle="inset" > backgroundColor="0xFFFFFF" > > > > > > segments="9" reflectionEnabled="true"/> > > > > > > > > > > > > <mx:HBox> > > > > > > <mx:Button label="item 1" > > > > > click="parentApplication.vsCreateMeals.selectedIndex=0;"/> > > > > > > <mx:Button label="side item 1" > > > > > click="parentApplication.vsCreateMeals.selectedIndex=1;"/> > > > > > > <mx:Button label="side item 2" > > > > > click="parentApplication.vsCreateMeals.selectedIndex=2;"/> > > > > > > </mx:HBox> > > > > > > </mx:Panel> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" > width="310" > > > > > height="320" > > > > > > title="{mealDetails.title}" horizontalAlign="center"> > > > > > > > > > > > > > > > > > > <mx:Metadata> > > > > > > [Event(name="addToMeal")] > > > > > > [Event(name="learnAboutThis")] > > > > > > </mx:Metadata> > > > > > > > > > > > > <mx:Script> > > > > > > <![CDATA[ > > > > > > import mx.controls.Alert; > > > > > > > > > > > > [Bindable] > > > > > > public var mealDetails:Object; > > > > > > > > > > > > > > > > > > private function calldispatch():void { > > > > > > parentApplication.createmeals_loadswf_var = mealDetails.swf; > > > > > > dispatchEvent(new Event('learnAboutThis', true)); > > > > > > > > > > > > } > > > > > > > > > > > > ]]> > > > > > > </mx:Script> > > > > > > > > > > > > <mx:Image source="{'/uploads/nutrition/' + > mealDetails.imgsource > > > }" > > > > > width="285" height="159"/> > > > > > > > > > > > > <mx:Label text="{mealDetails.serving}"/> > > > > > > > > > > > > <mx:Button label="Add to Meal" click="dispatchEvent(new > > > > > Event('addToMeal', true))"/> > > > > > > > > > > > > <mx:Button label="Learn About This" click="calldispatch()"/> > > > > > > > > > > > > </mx:Panel> > > > > > > > > > > > > > > > > > > > > > > > > --- In flexcoders@..., Sam Lai samuel.lai@ wrote: > > > > > > > > > > > > > > It seems like wherever this code is - > > > > > > > > > > > > > > [Bindable] > > > > > > > private var customMeals:ArrayCollection = new > ArrayCollection; > > > > > > > > > > > > > > //throws error on this line > > > > > > > customMeals.addItem((event.target as mealitem).mealDetails); > > > > > > > > > > > > > > event.target is actually the panel containing the 'create > meal > > > item' > > > > > > > button, as opposed to the mealitem itself. Can you post some > > > more of > > > > > > > the script and MXML for that part? > > > > > > > > > > > > > > The src folder is empty for me too in the ZIP file. > > > > > > > > > > > > > > 2009/7/2 Jason B nospam@: > > > > > > > > yes heres the results > > > > > > > > > > > > > > > > > "Main0.vsMain.HBox8.VBox968.vsCreateMeals.VBox971.pnlCreateBreakfast.cov\ > \ > > > \ > > > > > erflow.Panelcreatemealitem1006" > > > > > > > > > > > > > > > > How can I access the object data, it's in a file thats > under > > > the > > > > > folder /com/nutrition/file.mxml > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --- In flexcoders@..., Sam Lai <samuel.lai@> > > > wrote: > > > > > > > >> > > > > > > > >> I'd add a trace statement just before it to see what type > of > > > > > object > > > > > > > >> event.target is - it could be that the target is the UI > > > > > component, and > > > > > > > >> not the data object. > > > > > > > >> > > > > > > > >> //throws error on this line > > > > > > > >> trace(event.target); > > > > > > > >> customMeals.addItem((event.target as > mealitem).mealDetails); > > > > > > > >> > > > > > > > >> 2009/7/2 Jason B <nospam@>: > > > > > > > >> > I've got an problem when the user clicks on button "Add > to > > > > > Meal" it throws an error because it can't seem to reference the > data > > > in > > > > > mealDetails object inside the com/ directory? > > > > > > > >> > > > > > > > > >> > I'm trying to add the item to the list control. > > > > > > > >> > > > > > > > > >> > I have the code located here in case you want more > details > > > > > > > >> > http://files.getdropbox.com/u/228472/mealsflex.zip > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > [Bindable] > > > > > > > >> > private var customMeals:ArrayCollection = new > > > ArrayCollection; > > > > > > > >> > > > > > > > > >> > //throws error on this line > > > > > > > >> > customMeals.addItem((event.target as > > > mealitem).mealDetails); > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > <?xml version="1.0" encoding="utf-8"?> > > > > > > > >> > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" > > > width="310" > > > > > height="320" > > > > > > > >> > title="{mealDetails.title}" horizontalAlign="center"> > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > <mx:Metadata> > > > > > > > >> > [Event(name="addToMeal")] > > > > > > > >> > [Event(name="learnAboutThis")] > > > > > > > >> > </mx:Metadata> > > > > > > > >> > > > > > > > > >> > <mx:Script> > > > > > > > >> > <![CDATA[ > > > > > > > >> > import mx.controls.Alert; > > > > > > > >> > > > > > > > > >> > [Bindable] > > > > > > > >> > public var mealDetails:Object; > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > private function calldispatch():void { > > > > > > > >> > > > > > > parentApplication.createmeals_loadswf_var = mealDetails.swf; > > > > > > > >> > dispatchEvent(new > > > > > Event('learnAboutThis', true)); > > > > > > > >> > > > > > > > > >> > } > > > > > > > >> > > > > > > > > >> > ]]> > > > > > > > >> > </mx:Script> > > > > > > > >> > > > > > > > > >> > <mx:Image source="{'/uploads/nutrition/' + > > > > > mealDetails.imgsource }" width="285" height="159"/> > > > > > > > >> > > > > > > > > >> > <mx:Label text="{mealDetails.serving}"/> > > > > > > > >> > > > > > > > > >> > <mx:Button label="Add to Meal" click="dispatchEvent(new > > > > > Event('addToMeal', true))"/> > > > > > > > >> > > > > > > > > >> > <mx:Button label="Learn About This" > > > > > click="calldispatch()"/> > > > > > > > >> > > > > > > > > >> > </mx:Panel> > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > ------------------------------------ > > > > > > > >> > > > > > > > > >> > -- > > > > > > > >> > Flexcoders Mailing List > > > > > > > >> > FAQ: > > > > > http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > > > > > > >> > Alternative FAQ location: > > > > > > > > > https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-\ > \ > > > \ > > > > > 1e62079f6847 > > > > > > > >> > Search Archives: > > > > > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! > > > Groups > > > > > Links > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ------------------------------------ > > > > > > > > > > > > > > > > -- > > > > > > > > Flexcoders Mailing List > > > > > > > > FAQ: > > > > > http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > > > > > > > Alternative FAQ location: > > > > > > > > > https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-\ > \ > > > \ > > > > > 1e62079f6847 > > > > > > > > Search Archives: > > > > > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! > > > Groups > > > > > Links > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
|
|
Re: getting the xml data from a dispatched eventAll I can say is that if you paid someone to write it, you should be looking for a refund. -TH --- In flexcoders@..., "Jason B" <nospam@...> wrote: > > funny you mention that since I paid an experienced Flex Engineer to build this yet I'm stuck debugging it. > I'll see what I can do, guess it's time to learn, It's disappointing to hear it was built wrong. > > > --- In flexcoders@..., "Tim Hoff" TimHoff@ wrote: > > > > > > Hey Jason, > > > > When I created a new project with the code that you pasted, there were > > several bugs; including variable naming and component naming > > mis-matches, that had to be fixed; in order to even run the application. > > This is what happens when you just start with an idea and add on from > > there; instead of planning out the application first. Because of this, > > the code is all over the place. I might suggest taking a step > > backwards, and clean-up the code first. That will make it much easier > > to debug your issue. > > > > -TH > > > > --- In flexcoders@..., "Jason B" <nospam@> wrote: > > > > > > I had that import in the main mxml before i replied to your message > > and still get an error? > > > > > > > > > > > > --- In flexcoders@..., "Tim Hoff" TimHoff@ wrote: > > > > > > > > > > > > import com.nutrition.Panelcreatemealitem; > > > > > > > > -TH > > > > > > > > --- In flexcoders@..., "Jason B" <nospam@> wrote: > > > > > > > > > > > > > > > It wont accept your suggestions > > > > > > > > > > Severity and Description Path Resource Location Creation Time > > > > > 1120: Access of undefined property Panelcreatemealitem. /src > > Main.mxml > > > > line 105 1246801954900 468962 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --- In flexcoders@..., "Tim Hoff" TimHoff@ wrote: > > > > > > > > > > > > > > > > > > Wow, I've got to say; "What a mess." However, you can get it > > work > > > > > > with the following changes: > > > > > > > > > > > > [Bindable] > > > > > > private var customMeals:XMLListCollection = new > > XMLListCollection(); > > > > > > > > > > > > > > > > > > > > > > > > // addToMeal event Handler > > > > > > private function addToMealHandler(event:Event):void > > > > > > { > > > > > > customMeals.addItem((event.target as > > > > > > Panelcreatemealitem).mealDetails); > > > > > > Alert.show(customMeals.toString()); > > > > > > } > > > > > > > > > > > > You have some naming conflicts and, since you're dealing > > xml, > > > > > > you'll need to use an XMLListCollection; instead of an > > > > ArrayCollection. > > > > > > > > > > > > -TH > > > > > > > > > > > > --- In flexcoders@..., "Jason B" <nospam@> wrote: > > > > > > > > > > > > > > Heres my three mxml files two of which are under the com/ > > folder > > > > and > > > > > > get imported...hope that helps > > > > > > > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > > > > > > layout="vertical" > > > > > > > creationComplete="init()" styleName="plain" > > > > > > xmlns:nutrition="com.nutrition.*" > > > > > > > paddingLeft="10" paddingTop="10" paddingRight="10" > > > > paddingBottom="10"> > > > > > > > > > > > > > > <mx:Script> > > > > > > > <![CDATA[ > > > > > > > import mx.collections.ArrayCollection; > > > > > > > import mx.collections.ICollectionView; > > > > > > > import mx.collections.XMLListCollection; > > > > > > > import com.nutrition.MealItem; > > > > > > > import mx.controls.Alert; > > > > > > > import mx.rpc.events.FaultEvent; > > > > > > > import mx.rpc.events.ResultEvent; > > > > > > > import mx.rpc.http.HTTPService; > > > > > > > // initialize > > > > > > > private function init():void > > > > > > > { > > > > > > > //load calories > > > > > > > httpservice_load("/main.php/flexnutrition/loadcalories", > > > > > > this["loadcaloriesResultHandler"]); > > > > > > > > > > > > > > hsNutrition.send(); > > > > > > > addEventListener('addToMeal', addToMealHandler); > > > > > > > addEventListener('removeMeal', removeMealHandler); > > > > > > > addEventListener('learnAboutThis', learnaboutthisswf); > > > > > > > > > > > > > > > > > > > > > > > > > > > > } > > > > > > > > > > > > > > private function httpservice_load(url_src:String, > > > > > > resulthandler:Function):void{ > > > > > > > > > > > > > > httpService.url = url_src; > > > > > > > > > > > > > > //var tmp:String = resulthandler.toString(); > > > > > > > //if(tmp != "none") > > > > > > > httpService.addEventListener(ResultEvent.RESULT, > > resulthandler); > > > > > > > httpService.send(); > > > > > > > } > > > > > > > > > > > > > > private function learnaboutthisswf(event:Event):void{ > > > > > > > vfc_guy.load("/uploads/swf/" + loadswf_var); > > > > > > > > > > > > > > } > > > > > > > > > > > > > > [Bindable] > > > > > > > private var nutritionData:XML; > > > > > > > [Bindable] > > > > > > > private var maindata:XML; > > > > > > > [Bindable] > > > > > > > public var loadswf_var:String; > > > > > > > [Bindable] > > > > > > > public var createmeals_loadswf_var:String; > > > > > > > > > > > > > > //load all calories for main meals > > > > > > > private function > > loadcaloriesResultHandler(event:ResultEvent):void > > > > > > > { > > > > > > > maindata = event.result as XML; > > > > > > > vfc_guy.load("/uploads/swf/" + maindata.swf); > > > > > > > } > > > > > > > > > > > > > > // nutrition result handler > > > > > > > private function > > nutritionResultHandler(event:ResultEvent):void > > > > > > > { > > > > > > > nutritionData = event.result as XML; > > > > > > > } > > > > > > > // nutrition fault handler > > > > > > > private function > > > > > > > { > > > > > > > Alert.show(event.toString()); > > > > > > > } > > > > > > > > > > > > > > // create breakfast > > > > > > > private function createBreakfast():void > > > > > > > { > > > > > > > vsMain.selectedIndex = 1; > > > > > > > plantype = 'Breakfast'; > > > > > > > } > > > > > > > // create lunch > > > > > > > private function createLunch():void > > > > > > > { > > > > > > > vsMain.selectedIndex = 1; > > > > > > > plantype = 'Lunch'; > > > > > > > } > > > > > > > // create dinner > > > > > > > private function createDinner():void > > > > > > > { > > > > > > > vsMain.selectedIndex = 1; > > > > > > > plantype = 'Dinner'; > > > > > > > } > > > > > > > > > > > > > > [Bindable] > > > > > > > private var plantype:String; > > > > > > > > > > > > > > [Bindable] > > > > > > > private var customMeals:ArrayCollection = new > > > > > > > > > > > > > > // addToMeal event Handler > > > > > > > private function addToMealHandler(event:Event):void > > > > > > > { > > > > > > > trace(event.target); > > > > > > > //customMeals.addItem((event.target as mealitem).mealDetails); > > > > > > > Alert.show(event.toString()); > > > > > > > > > > > > > > } > > > > > > > > > > > > > > // removeMeal event Handler > > > > > > > private function removeMealHandler(event:Event):void > > > > > > > { > > > > > > > customMeals.removeItemAt(ls.selectedIndex); > > > > > > > } > > > > > > > > > > > > > > ]]> > > > > > > > </mx:Script> > > > > > > > > > > > > > > <mx:HTTPService id="hsNutrition" > > > > > > url="/main.php/flexnutrition/nutritioncal" > > > > > > > result="nutritionResultHandler(event)" > > > > > > > fault="nutritionFaultHandler(event)" resultFormat="e4x"/> > > > > > > > > > > > > > > <mx:HTTPService id="httpService" url="" > > > > > > > > > > > > > > <mx:Label id="totalcalories" text="{'Today\'s Meal Plan is > > based > > > > on a > > > > > > ' + maindata.totalcalories + ' Calorie Diet'}" fontWeight="bold" > > > > > > fontSize="18"/> > > > > > > > > > > > > > > <!--mx:Button label="Print Meal Menu" /--> > > > > > > > > > > > > > > <mx:ViewStack id="vsMain" width="100%" height="100%"> > > > > > > > > > > > > > > <mx:Canvas id="nutrition_canvas" width="100%" height="100%"> > > > > > > > > > > > > > > <mx:SWFLoader id="vfc_guy" source="" height="400" width="400" > > > > > > autoLoad="true" x="700" y="100" /> > > > > > > > > > > > > > > <mx:HBox width="100%" height="100%"> > > > > > > > > > > > > > > <mx:VBox width="40%" height="100%"> > > > > > > > > > > > > > > <nutrition:MealPanel id="pnlBreakfast" > > > > > > meal="{nutritionData.breakfast}" > > > > > > > title="Breakfast : Please select one meal from > > > > > > below({maindata.breakfast} Cal Goal)"/> > > > > > > > > > > > > > > <mx:HBox horizontalCenter="right"> > > > > > > > <mx:Button label="Create your own Breakfast" > > > > > > click="createBreakfast()"/> > > > > > > > </mx:HBox> > > > > > > > > > > > > > > > > > > > > > <nutrition:MealPanel id="pnlSnack1" > > meal="{nutritionData.snack1}" > > > > > > > title="Snack : Please select one snack from > > > > below({maindata.snack1} > > > > > > Cal Goal)"/> > > > > > > > <!--mx:Button label="Create your own Lunch" > > > > click="createLunch()"/--> > > > > > > > > > > > > > > <nutrition:MealPanel id="pnlLunch" > > meal="{nutritionData.lunch}" > > > > > > > title="Lunch : Please select one meal from > > below({maindata.lunch} > > > > Cal > > > > > > Goal)"/> > > > > > > > > > > > > > > <nutrition:MealPanel id="pnlSnack2" > > meal="{nutritionData.snack2}" > > > > > > > title="Snack : Please select one snack from > > > > below({maindata.snack2} > > > > > > Cal Goal)"/> > > > > > > > <!--mx:Button label="Create your own Dinner" > > > > > > click="createDinner()"/--> > > > > > > > > > > > > > > <nutrition:MealPanel id="pnlDinner" > > meal="{nutritionData.dinner}" > > > > > > > title="Dinner : Please select one meal from > > > > below({maindata.dinner} > > > > > > Cal Goal)"/> > > > > > > > > > > > > > > <nutrition:MealPanel id="pnlSnack3" > > meal="{nutritionData.snack3}" > > > > > > > title="Snack : Please select one snack from > > > > below({maindata.snack3} > > > > > > Cal Goal)"/> > > > > > > > </mx:VBox> > > > > > > > > > > > > > > > > > > > > > </mx:HBox> > > > > > > > </mx:Canvas> > > > > > > > > > > > > > > > > > > > > > <mx:HBox width="100%" height="100%"> > > > > > > > > > > > > > > <mx:VBox width="30%" height="100%"> > > > > > > > <mx:HBox> > > > > > > > <mx:Label text="{'My Custom ' + plantype}"/> > > > > > > > > > > > > > > </mx:HBox> > > > > > > > > > > > > > > <mx:List id="ls" dataProvider="{customMeals}" > > > > > > > <mx:itemRenderer> > > > > > > > <mx:Component> > > > > > > > <mx:VBox> > > > > > > > <mx:Image width="100" height="100"/> > > > > > > > <mx:Button label="Remove" click="dispatchEvent(new > > > > Event('removeMeal', > > > > > > true))"/> > > > > > > > <mx:Label text="{data.serving}"/> > > > > > > > </mx:VBox> > > > > > > > </mx:Component> > > > > > > > </mx:itemRenderer> > > > > > > > </mx:List> > > > > > > > </mx:VBox> > > > > > > > > > > > > > > <mx:VBox width="100%" height="100%"> > > > > > > > > > > > > > > <!--mx:Label text="Please select ONE ITEM from list > > > > > > > <mx:ViewStack width="40%" height="410" borderStyle="inset" > > > > > > borderThickness="2" id="vsCreateMeals"> > > > > > > > > > > > > > > <mx:VBox > > > > > > > > <nutrition:Panelcreatemeal id="pnlCreateBreakfast" > > > > > > meal="{nutritionData.breakfast}"/> > > > > > > > </mx:VBox> > > > > > > > > > > > > > > <mx:VBox > > > > > > > > <nutrition:Panelcreatemeal id="pnlCreateLunch" > > > > > > meal="{nutritionData.lunch}"/> > > > > > > > </mx:VBox> > > > > > > > > > > > > > > <mx:VBox > > > > > > > > <nutrition:Panelcreatemeal id="pnlCreateDinner" > > > > > > meal="{nutritionData.dinner}"/> > > > > > > > </mx:VBox> > > > > > > > > > > > > > > </mx:ViewStack> > > > > > > > <mx:HBox> > > > > > > > <mx:Button label="Save" click="vsMain.selectedIndex = > > > > > > > <mx:Button label="Cancel" click="vsMain.selectedIndex = 0;"/> > > > > > > > </mx:HBox> > > > > > > > > > > > > > > </mx:VBox> > > > > > > > > > > > > > > > > > > > > > </mx:HBox> > > > > > > > > > > > > > > </mx:ViewStack> > > > > > > > > > > > > > > </mx:Application> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > > > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" > > width="100%" > > > > > > height="390" > > > > > > > borderThicknessLeft="0" borderThicknessRight="0" > > > > > > borderThicknessBottom="0" > > > > > > > dropShadowEnabled="false" > > > > > > > horizontalAlign="center" > > > > > > xmlns:containers="com.dougmccune.containers.*" title="Select > > Item > > > > > > from below"> > > > > > > > > > > > > > > <mx:Script> > > > > > > > <![CDATA[ > > > > > > > //import com.createmealPanel; > > > > > > > > > > > > > > [Bindable] > > > > > > > private var _meal:XMLList; > > > > > > > > > > > > > > public function set meal(value:XMLList):void > > > > > > > { > > > > > > > if(value) > > > > > > > { > > > > > > > _meal = value; > > > > > > > createContainers(); > > > > > > > } > > > > > > > } > > > > > > > > > > > > > > private function createContainers():void > > > > > > > { > > > > > > > for each(var item:Object in _meal.itemdata) > > > > > > > { > > > > > > > if(item.available == "yes") > > > > > > > { > > > > > > > var mealitem:Panelcreatemealitem = new > > > > > > > coverflow.addChild(mealitem); > > > > > > > mealitem.mealDetails = item; > > > > > > > } > > > > > > > } > > > > > > > } > > > > > > > ]]> > > > > > > > </mx:Script> > > > > > > > > > > > > > > <containers:CoverFlowContainer id="coverflow" width="100%" > > > > > > height="100%" > > > > > > > horizontalGap="1" borderStyle="inset" > > backgroundColor="0xFFFFFF" > > > > > > > segments="9" reflectionEnabled="true"/> > > > > > > > > > > > > > > <mx:HBox> > > > > > > > <mx:Button label="item 1" > > > > > > click="parentApplication.vsCreateMeals.selectedIndex=0;"/> > > > > > > > <mx:Button label="side item 1" > > > > > > click="parentApplication.vsCreateMeals.selectedIndex=1;"/> > > > > > > > <mx:Button label="side item 2" > > > > > > click="parentApplication.vsCreateMeals.selectedIndex=2;"/> > > > > > > > </mx:HBox> > > > > > > > </mx:Panel> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > > > > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" > > width="310" > > > > > > height="320" > > > > > > > title="{mealDetails.title}" horizontalAlign="center"> > > > > > > > > > > > > > > > > > > > > > <mx:Metadata> > > > > > > > [Event(name="addToMeal")] > > > > > > > [Event(name="learnAboutThis")] > > > > > > > </mx:Metadata> > > > > > > > > > > > > > > <mx:Script> > > > > > > > <![CDATA[ > > > > > > > import mx.controls.Alert; > > > > > > > > > > > > > > [Bindable] > > > > > > > public var mealDetails:Object; > > > > > > > > > > > > > > > > > > > > > private function calldispatch():void { > > > > > > > parentApplication.createmeals_loadswf_var = > > > > > > > dispatchEvent(new Event('learnAboutThis', true)); > > > > > > > > > > > > > > } > > > > > > > > > > > > > > ]]> > > > > > > > </mx:Script> > > > > > > > > > > > > > > <mx:Image source="{'/uploads/nutrition/' + > > mealDetails.imgsource > > > > }" > > > > > > width="285" height="159"/> > > > > > > > > > > > > > > <mx:Label text="{mealDetails.serving}"/> > > > > > > > > > > > > > > <mx:Button label="Add to Meal" click="dispatchEvent(new > > > > > > Event('addToMeal', true))"/> > > > > > > > > > > > > > > <mx:Button label="Learn About This" > > > > > > > > > > > > > > </mx:Panel> > > > > > > > > > > > > > > > > > > > > > > > > > > > > --- In flexcoders@..., Sam Lai samuel.lai@ wrote: > > > > > > > > > > > > > > > > It seems like wherever this code is - > > > > > > > > > > > > > > > > [Bindable] > > > > > > > > private var customMeals:ArrayCollection = new > > ArrayCollection; > > > > > > > > > > > > > > > > //throws error on this line > > > > > > > > customMeals.addItem((event.target as mealitem).mealDetails); > > > > > > > > > > > > > > > > event.target is actually the panel containing the 'create > > meal > > > > item' > > > > > > > > button, as opposed to the mealitem itself. Can you post some > > > > more of > > > > > > > > the script and MXML for that part? > > > > > > > > > > > > > > > > The src folder is empty for me too in the ZIP file. > > > > > > > > > > > > > > > > 2009/7/2 Jason B nospam@: > > > > > > > > > yes heres the results > > > > > > > > > > > > > > > > > > > > > \ > > \ > > > > \ > > > > > > erflow.Panelcreatemealitem1006" > > > > > > > > > > > > > > > > > > How can I access the object data, it's in a file thats > > under > > > > the > > > > > > folder /com/nutrition/file.mxml > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --- In flexcoders@..., Sam Lai > > > > wrote: > > > > > > > > >> > > > > > > > > >> I'd add a trace statement just before it to see what type > > of > > > > > > object > > > > > > > > >> event.target is - it could be that the target is the UI > > > > > > component, and > > > > > > > > >> not the data object. > > > > > > > > >> > > > > > > > > >> //throws error on this line > > > > > > > > >> trace(event.target); > > > > > > > > >> customMeals.addItem((event.target as > > mealitem).mealDetails); > > > > > > > > >> > > > > > > > > >> 2009/7/2 Jason B <nospam@>: > > > > > > > > >> > I've got an problem when the user clicks on button > > to > > > > > > Meal" it throws an error because it can't seem to reference the > > data > > > > in > > > > > > mealDetails object inside the com/ directory? > > > > > > > > >> > > > > > > > > > >> > I'm trying to add the item to the list control. > > > > > > > > >> > > > > > > > > > >> > I have the code located here in case you want more > > details > > > > > > > > >> > http://files.getdropbox.com/u/228472/mealsflex.zip > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > [Bindable] > > > > > > > > >> > private var customMeals:ArrayCollection = new > > > > ArrayCollection; > > > > > > > > >> > > > > > > > > > >> > //throws error on this line > > > > > > > > >> > customMeals.addItem((event.target as > > > > mealitem).mealDetails); > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > <?xml version="1.0" encoding="utf-8"?> > > > > > > > > >> > <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" > > > > width="310" > > > > > > height="320" > > > > > > > > >> > title="{mealDetails.title}" > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > <mx:Metadata> > > > > > > > > >> > [Event(name="addToMeal")] > > > > > > > > >> > [Event(name="learnAboutThis")] > > > > > > > > >> > </mx:Metadata> > > > > > > > > >> > > > > > > > > > >> > <mx:Script> > > > > > > > > >> > <![CDATA[ > > > > > > > > >> > import mx.controls.Alert; > > > > > > > > >> > > > > > > > > > >> > [Bindable] > > > > > > > > >> > public var mealDetails:Object; > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > private function calldispatch():void { > > > > > > > > >> > > > > > > > parentApplication.createmeals_loadswf_var = mealDetails.swf; > > > > > > > > >> > dispatchEvent(new > > > > > > Event('learnAboutThis', true)); > > > > > > > > >> > > > > > > > > > >> > } > > > > > > > > >> > > > > > > > > > >> > ]]> > > > > > > > > >> > </mx:Script> > > > > > > > > >> > > > > > > > > > >> > <mx:Image source="{'/uploads/nutrition/' + > > > > > > mealDetails.imgsource }" width="285" height="159"/> > > > > > > > > >> > > > > > > > > > >> > <mx:Label text="{mealDetails.serving}"/> > > > > > > > > >> > > > > > > > > > >> > <mx:Button label="Add to Meal" > > > > > > Event('addToMeal', true))"/> > > > > > > > > >> > > > > > > > > > >> > <mx:Button label="Learn About This" > > > > > > click="calldispatch()"/> > > > > > > > > >> > > > > > > > > > >> > </mx:Panel> > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > ------------------------------------ > > > > > > > > >> > > > > > > > > > >> > -- > > > > > > > > >> > Flexcoders Mailing List > > > > > > > > >> > FAQ: > > > > > > > > > > > > > > >> > Alternative FAQ location: > > > > > > > > > > > > https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-\ \ > > \ > > > > \ > > > > > > 1e62079f6847 > > > > > > > > >> > Search Archives: > > > > > > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! > > > > Groups > > > > > > Links > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ------------------------------------ > > > > > > > > > > > > > > > > > > -- > > > > > > > > > Flexcoders Mailing List > > > > > > > > > FAQ: > > > > > > > > > > > > > > > Alternative FAQ location: > > > > > > > > > > > > https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-\ \ > > \ > > > > \ > > > > > > 1e62079f6847 > > > > > > > > > Search Archives: > > > > > > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! > > > > Groups > > > > > > Links > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
|
|
RE: Re: getting the xml data from a dispatched eventYou didn't use one of those $20/hour offshore services did you?
I did not look at your code myself, but Tim's analysis will be accurate. Tracy Spratt, Lariat Services, development services available _____ From: flexcoders@... [mailto:flexcoders@...] On Behalf Of Tim Hoff Sent: Monday, July 06, 2009 12:24 PM To: flexcoders@... Subject: [flexcoders] Re: getting the xml data from a dispatched event All I can say is that if you paid someone to write it, you should be looking for a refund. -TH --- In flexcoders@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com, "Jason B" <nospam@...> wrote: > > funny you mention that since I paid an experienced Flex Engineer to build this yet I'm stuck debugging it. > I'll see what I can do, guess it's time to learn, It's disappointing to hear it was built wrong. > > > --- In flexcoders@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com, "Tim Hoff" TimHoff@ wrote: > > > > > > Hey Jason, > > > > When I created a new project with the code that you pasted, there were > > several bugs; including variable naming and component naming > > mis-matches, that had to be fixed; in order to even run the application. > > This is what happens when you just start with an idea and add on from > > there; instead of planning out the application first. Because of this, > > the code is all over the place. I might suggest taking a step > > backwards, and clean-up the code first. That will make it much easier > > to debug your issue. > > > > -TH > > > > --- In flexcoders@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com, "Jason B" <nospam@> wrote: > > > > > > I had that import in the main mxml before i replied to your message > > and still get an error? > > > > > > > > > > > > --- In flexcoders@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com, "Tim Hoff" TimHoff@ wrote: > > > > > > > > > > > > import com.nutrition.Panelcreatemealitem; > > > > > > > > -TH > > > > > > > > --- In flexcoders@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com, "Jason B" <nospam@> wrote: > > > > > > > > > > > > > > > It wont accept your suggestions > > > > > > > > > > Severity and Description Path Resource Location Creation Time Id > > > > > 1120: Access of undefined property Panelcreatemealitem. /src > > Main.mxml > > > > line 105 1246801954900 468962 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --- In flexcoders@yahoogro <mailto:flexcoders%40yahoogroups.com> > > > > > > > > > > > > > > > > > > Wow, I've got to say; "What a mess." However, you can get it to > > work > > > > > > with the following changes: > > > > > > > > > > > > [Bindable] > > > > > > private var customMeals:XMLListCollection = new > > XMLListCollection(); > > > > > > > > > > > > > > > > > > > > > > > > // addToMeal event Handler > > > > > > private function addToMealHandler(event:Event):void > > > > > > { > > > > > > customMeals.addItem((event.target as > > > > > > Panelcreatemealitem).mealDetails); > > > > > > Alert.show(customMeals.toString()); > > > > > > } > > > > > > > > > > > > You have some naming conflicts and, since you're dealing > > xml, > > > > > > you'll need to use an XMLListCollection; instead of an > > > > ArrayCollection. > > > > > > > > > > > > -TH > > > > > > > > > > > > --- In flexcoders@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com, "Jason B" <nospam@> wrote: > > > > > > > > > > > > > > Heres my three mxml files two of which are under the com/ > > folder > > > > and > > > > > > get imported...hope that helps > > > > > > > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > > > > <mx:Application xmlns:mx="http://www.adobe. <http://www.adobe.com/2006/mxml> com/2006/mxml" > > > > > > layout="vertical" > > > > > > > creationComplete="init()" styleName="plain" > > > > > > xmlns:nutrition="com.nutrition.*" > > > > > > > paddingLeft="10" paddingTop="10" paddingRight="10" > > > > paddingBottom="10"> > > > > > > > > > > > > > > <mx:Script> > > > > > > > <![CDATA[ > > > > > > > import mx.collections.ArrayCollection; > > > > > > > import mx.collections.ICollectionView; > > > > > > > import mx.collections.XMLListCollection; > > > > > > > import com.nutrition.MealItem; > > > > > > > import mx.controls.Alert; > > > > > > > import mx.rpc.events.FaultEvent; > > > > > > > import mx.rpc.events.ResultEvent; > > > > > > > import mx.rpc.http.HTTPService; > > > > > > > // initialize > > > > > > > private function init():void > > > > > > > { > > > > > > > //load calories > > > > > > > httpservice_load("/main.php/flexnutrition/loadcalories", > > > > > > this["loadcaloriesResultHandler"]); > > > > > > > > > > > > > > hsNutrition.send(); > > > > > > > addEventListener('addToMeal', addToMealHandler); > > > > > > > addEventListener('removeMeal', removeMealHandler); > > > > > > > addEventListener('learnAboutThis', learnaboutthisswf); > > > > > > > > > > > > > > > > > > > > > > > > > > > > } > > > > > > > > > > > > > > private function httpservice_load(url_src:String, > > > > > > resulthandler:Function):void{ > > > > > > > > > > > > > > httpService.url = url_src; > > > > > > > > > > > > > > //var tmp:String = resulthandler.toString(); > > > > > > > //if(tmp != "none") > > > > > > > httpService.addEventListener(ResultEvent.RESULT, > > resulthandler); > > > > > > > httpService.send(); > > > > > > > } > > > > > > > > > > > > > > private function learnaboutthisswf(event:Event):void{ > > > > > > > vfc_guy.load("/uploads/swf/" + loadswf_var); > > > > > > > > > > > > > > } > > > > > > > > > > > > > > [Bindable] > > > > > > > private var nutritionData:XML; > > > > > > > [Bindable] > > > > > > > private var maindata:XML; > > > > > > > [Bindable] > > > > > > > public var loadswf_var:String; > > > > > > > [Bindable] > > > > > > > public var createmeals_loadswf_var:String; > > > > > > > > > > > > > > //load all calories for main meals > > > > > > > private function > > loadcaloriesResultHandler(event:ResultEvent):void > > > > > > > { > > > > > > > maindata = event.result as XML; > > > > > > > vfc_guy.load("/uploads/swf/" + maindata.swf); > > > > > > > } > > > > > > > > > > > > > > // nutrition result handler > > > > > > > private function > > nutritionResultHandler(event:ResultEvent):void > > > > > > > { > > > > > > > nutritionData = event.result as XML; > > > > > > > } > > > > > > > // nutrition fault handler > > > > > > > private function > > > > > > > { > > > > > > > Alert.show(event.toString()); > > > > > > > } > > > > > > > > > > > > > > // create breakfast > > > > > > > private function createBreakfast():void > > > > > > > { > > > > > > > vsMain.selectedIndex = 1; > > > > > > > plantype = 'Breakfast'; > > > > > > > } > > > > > > > // create lunch > > > > > > > private function createLunch():void > > > > > > > { > > > > > > > vsMain.selectedIndex = 1; > > > > > > > plantype = 'Lunch'; > > > > > > > } > > > > > > > // create dinner > > > > > > > private function createDinner():void > > > > > > > { > > > > > > > vsMain.selectedIndex = 1; > > > > > > > plantype = 'Dinner'; > > > > > > > } > > > > > > > > > > > > > > [Bindable] > > > > > > > private var plantype:String; > > > > > > > > > > > > > > [Bindable] > > > > > > > private var customMeals:ArrayCollection = new > > > > > > > > > > > > > > // addToMeal event Handler > > > > > > > private function addToMealHandler(event:Event):void > > > > > > > { > > > > > > > trace(event.target); > > > > > > > //customMeals.addItem((event.target as mealitem).mealDetails); > > > > > > > Alert.show(event.toString()); > > > > > > > > > > > > > > } > > > > > > > > > > > > > > // removeMeal event Handler > > > > > > > private function removeMealHandler(event:Event):void > > > > > > > { > > > > > > > customMeals.removeItemAt(ls.selectedIndex); > > > > > > > } > > > > > > > > > > > > > > ]]> > > > > > > > </mx:Script> > > > > > > > > > > > > > > <mx:HTTPService id="hsNutrition" > > > > > > url="/main.php/flexnutrition/nutritioncal" > > > > > > > result="nutritionResultHandler(event)" > > > > > > > fault="nutritionFaultHandler(event)" resultFormat="e4x"/> > > > > > > > > > > > > > > <mx:HTTPService id="httpService" url="" > > > > > > > > > > > > > > <mx:Label id="totalcalories" text="{'Today\'s Meal Plan is > > based > > > > on a > > > > > > ' + maindata.totalcalories + ' Calorie Diet'}" fontWeight="bold" > > > > > > fontSize="18"/> > > > > > > > > > > > > > > <!--mx:Button label="Print Meal Menu" /--> > > > > > > > > > > > > > > <mx:ViewStack id="vsMain" width="100%" height="100%"> > > > > > > > > > > > > > > <mx:Canvas id="nutrition_canvas" width="100%" height="100%"> > > > > > > > > > > > > > > <mx:SWFLoader id="vfc_guy" source="" height="400" width="400" > > > > > > autoLoad="true" x="700" y="100" /> > > > > > > > > > > > > > > <mx:HBox width="100%" height="100%"> > > > > > > > > > > > > > > <mx:VBox width="40%" height="100%"> > > > > > > > > > > > > > > <nutrition:MealPanel id="pnlBreakfast" > > > > > > meal="{nutritionData.breakfast}" > > > > > > > title="Breakfast : Please select one meal from > > > > > > below({maindata.breakfast} Cal Goal)"/> > > > > > > > > > > > > > > <mx:HBox horizontalCenter="right"> > > > > > > > <mx:Button label="Create your own Breakfast" > > > > > > click="createBreakfast()"/> > > > > > > > </mx:HBox> > > > > > > > > > > > > > > > > > > > > > <nutrition:MealPanel id="pnlSnack1" > > meal="{nutritionData.snack1}" > > > > > > > title="Snack : Please select one snack from > > > > below({maindata.snack1} > > > > > > Cal Goal)"/> > > > > > > > <!--mx:Button label="Create your own Lunch" > > > > click="createLunch()"/--> > > > > > > > > > > > > > > <nutrition:MealPanel id="pnlLunch" > > meal="{nutritionData.lunch}" > > > > > > > title="Lunch : Please select one meal from > > below({maindata.lunch} > > > > Cal > > > > > > Goal)"/> > > > > > > > > > > > > > > <nutrition:MealPanel id="pnlSnack2" > > meal="{nutritionData.snack2}" > > > > > > > title="Snack : Please select one snack from > > > > below({maindata.snack2} > > > > > > Cal Goal)"/> > > > > > > > <!--mx:Button label="Create your own Dinner" > > > > > > click="createDinner()"/--> > > > > > > > > > > > > > > <nutrition:MealPanel id="pnlDinner" > > meal="{nutritionData.dinner}" > > > > > > > title="Dinner : Please select one meal from > > > > below({maindata.dinner} > > > > > > Cal Goal)"/> > > > > > > > > > > > > > > <nutrition:MealPanel id="pnlSnack3" > > meal="{nutritionData.snack3}" > > > > > > > title="Snack : Please select one snack from > > > > below({maindata.snack3} > > > > > > Cal Goal)"/> > > > > > > > </mx:VBox> > > > > > > > > > > > > > > > > > > > > > </mx:HBox> > > > > > > > </mx:Canvas> > > > > > > > > > > > > > > > > > > > > > <mx:HBox width="100%" height="100%"> > > > > > > > > > > > > > > <mx:VBox width="30%" height="100%"> > > > > > > > <mx:HBox> > > > > > > > <mx:Label text="{'My Custom ' + plantype}"/> > > > > > > > > > > > > > > </mx:HBox> > > > > > > > > > > > > > > <mx:List id="ls" dataProvider="{customMeals}" > > > > > > > <mx:itemRenderer> > > > > > > > <mx:Component> > > > > > > > <mx:VBox> > > > > > > > <mx:Image width="100" height="100"/> > > > > > > > <mx:Button label="Remove" click="dispatchEvent(new > > > > Event('removeMeal', > > > > > > true))"/> > > > > > > > <mx:Label text="{data.serving}"/> > > > > > > > </mx:VBox> > > > > > > > </mx:Component> > > > > > > > </mx:itemRenderer> > > > > > > > </mx:List> > > > > > > > </mx:VBox> > > > > > > > > > > > > > > <mx:VBox width="100%" height="100%"> > > > > > > > > > > > > > > <!--mx:Label text="Please select ONE ITEM from list > > > > > > > <mx:ViewStack width="40%" height="410" borderStyle="inset" > > > > > > borderThickness="2" id="vsCreateMeals"> > > > > > > > > > > > > > > <mx:VBox > > > > > > > > <nutrition:Panelcreatemeal id="pnlCreateBreakfast" > > > > > > meal="{nutritionData.breakfast}"/> > > > > > > > </mx:VBox> > > > > > > > > > > > > > > <mx:VBox > > > > > > > > <nutrition:Panelcreatemeal id="pnlCreateLunch" > > > > > > meal="{nutritionData.lunch}"/> > > > > > > > </mx:VBox> > > > > > > > > > > > > > > <mx:VBox > > > > > > > > <nutrition:Panelcreatemeal id="pnlCreateDinner" > > > > > > meal="{nutritionData.dinner}"/> > > > > > > > </mx:VBox> > > > > > > > > > > > > > > </mx:ViewStack> > > > > > > > <mx:HBox> > > > > > > > <mx:Button label="Save" click="vsMain.selectedIndex = > > > > > > > <mx:Button label="Cancel" click="vsMain.selectedIndex = 0;"/> > > > > > > > </mx:HBox> > > > > > > > > > > > > > > </mx:VBox> > > > > > > > > > > > > > > > > > > > > > </mx:HBox> > > > > > > > > > > > > > > </mx:ViewStack> > > > > > > > > > > > > > > </mx:Application> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > > > > <mx:Panel xmlns:mx="http://www.adobe. > > width="100%" > > > > > > height="390" > > > > > > > borderThicknessLeft="0" borderThicknessRight="0" > > > > > > borderThicknessBottom="0" > > > > > > > dropShadowEnabled="false" > > > > > > > horizontalAlign="center" > > > > > > xmlns:containers="com.dougmccune.containers.*" title="Select An > > Item > > > > > > from below"> > > > > > > > > > > > > > > <mx:Script> > > > > > > > <![CDATA[ > > > > > > > //import com.createmealPanel; > > > > > > > > > > > > > > [Bindable] > > > > > > > private var _meal:XMLList; > > > > > > > > > > > > > > public function set meal(value:XMLList):void > > > > > > > { > > > > > > > if(value) > > > > > > > { > > > > > > > _meal = value; > > > > > > > createContainers(); > > > > > > > } > > > > > > > } > > > > > > > > > > > > > > private function createContainers():void > > > > > > > { > > > > > > > for each(var item:Object in _meal.itemdata) > > > > > > > { > > > > > > > if(item.available == "yes") > > > > > > > { > > > > > > > var mealitem:Panelcreatemealitem = new > > > > > > > coverflow.addChild(mealitem); > > > > > > > mealitem.mealDetails = item; > > > > > > > } > > > > > > > } > > > > > > > } > > > > > > > ]]> > > > > > > > </mx:Script> > > > > > > > > > > > > > > <containers:CoverFlowContainer id="coverflow" width="100%" > > > > > > height="100%" > > > > > > > horizontalGap="1" borderStyle="inset" > > backgroundColor="0xFFFFFF" > > > > > > > segments="9" reflectionEnabled="true"/> > > > > > > > > > > > > > > <mx:HBox> > > > > > > > <mx:Button label="item 1" > > > > > > click="parentApplication.vsCreateMeals.selectedIndex=0;"/> > > > > > > > <mx:Button label="side item 1" > > > > > > click="parentApplication.vsCreateMeals.selectedIndex=1;"/> > > > > > > > <mx:Button label="side item 2" > > > > > > click="parentApplication.vsCreateMeals.selectedIndex=2;"/> > > > > > > > </mx:HBox> > > > > > > > </mx:Panel> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > > > > <mx:Panel xmlns:mx="http://www.adobe. > > width="310" > > > > > > height="320" > > > > > > > title="{mealDetails.title}" horizontalAlign="center"> > > > > > > > > > > > > > > > > > > > > > <mx:Metadata> > > > > > > > [Event(name="addToMeal")] > > > > > > > [Event(name="learnAboutThis")] > > > > > > > </mx:Metadata> > > > > > > > > > > > > > > <mx:Script> > > > > > > > <![CDATA[ > > > > > > > import mx.controls.Alert; > > > > > > > > > > > > > > [Bindable] > > > > > > > public var mealDetails:Object; > > > > > > > > > > > > > > > > > > > > > private function calldispatch():void { > > > > > > > parentApplication.createmeals_loadswf_var = > > > > > > > dispatchEvent(new Event('learnAboutThis', true)); > > > > > > > > > > > > > > } > > > > > > > > > > > > > > ]]> > > > > > > > </mx:Script> > > > > > > > > > > > > > > <mx:Image source="{'/uploads/nutrition/' + > > mealDetails.imgsource > > > > }" > > > > > > width="285" height="159"/> > > > > > > > > > > > > > > <mx:Label text="{mealDetails.serving}"/> > > > > > > > > > > > > > > <mx:Button label="Add to Meal" click="dispatchEvent(new > > > > > > Event('addToMeal', true))"/> > > > > > > > > > > > > > > <mx:Button label="Learn About This" > > > > > > > > > > > > > > </mx:Panel> > > > > > > > > > > > > > > > > > > > > > > > > > > > > --- In flexcoders@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com, Sam Lai samuel.lai@ wrote: > > > > > > > > > > > > > > > > It seems like wherever this code is - > > > > > > > > > > > > > > > > [Bindable] > > > > > > > > private var customMeals:ArrayCollection = new > > ArrayCollection; > > > > > > > > > > > > > > > > //throws error on this line > > > > > > > > customMeals.addItem((event.target as mealitem).mealDetails); > > > > > > > > > > > > > > > > event.target is actually the panel containing the 'create > > meal > > > > item' > > > > > > > > button, as opposed to the mealitem itself. Can you post some > > > > more of > > > > > > > > the script and MXML for that part? > > > > > > > > > > > > > > > > The src folder is empty for me too in the ZIP file. > > > > > > > > > > > > > > > > 2009/7/2 Jason B nospam@: > > > > > > > > > yes heres the results > > > > > > > > > > > > > > > > > > > > > \ > > \ > > > > \ > > > > > > erflow.Panelcreatemealitem1006" > > > > > > > > > > > > > > > > > > How can I access the object data, it's in a file thats > > under > > > > the > > > > > > folder /com/nutrition/file.mxml > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --- In flexcoders@yahoogro <samuel.lai@> > > > > wrote: > > > > > > > > >> > > > > > > > > >> I'd add a trace statement just before it to see what type > > of > > > > > > object > > > > > > > > >> event.target is - it could be that the target is the UI > > > > > > component, and > > > > > > > > >> not the data object. > > > > > > > > >> > > > > > > > > >> //throws error on this line > > > > > > > > >> trace(event.target); > > > > > > > > >> customMeals.addItem((event.target as > > mealitem).mealDetails); > > > > > > > > >> > > > > > > > > >> 2009/7/2 Jason B <nospam@>: > > > > > > > > >> > I've got an problem when the user clicks on button > > to > > > > > > Meal" it throws an error because it can't seem to reference the > > data > > > > in > > > > > > mealDetails object inside the com/ directory? > > > > > > > > >> > > > > > > > > > >> > I'm trying to add the item to the list control. > > > > > > > > >> > > > > > > > > > >> > I have the code located here in case you want more > > details > > > > > > > > >> > http://files. <http://files.getdropbox.com/u/228472/mealsflex.zip> getdropbox.com/u/228472/mealsflex.zip > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > [Bindable] > > > > > > > > >> > private var customMeals:ArrayCollection = new > > > > ArrayCollection; > > > > > > > > >> > > > > > > > > > >> > //throws error on this line > > > > > > > > >> > customMeals.addItem((event.target as > > > > mealitem).mealDetails); > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > <?xml version="1.0" encoding="utf-8"?> > > > > > > > > >> > <mx:Panel xmlns:mx="http://www.adobe. > > > > width="310" > > > > > > height="320" > > > > > > > > >> > title="{mealDetails.title}" horizontalAlign="center"> > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > <mx:Metadata> > > > > > > > > >> > [Event(name="addToMeal")] > > > > > > > > >> > [Event(name="learnAboutThis")] > > > > > > > > >> > </mx:Metadata> > > > > > > > > >> > > > > > > > > > >> > <mx:Script> > > > > > > > > >> > <![CDATA[ > > > > > > > > >> > import mx.controls.Alert; > > > > > > > > >> > > > > > > > > > >> > [Bindable] > > > > > > > > >> > public var mealDetails:Object; > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > private function calldispatch():void { > > > > > > > > >> > > > > > > > parentApplication.createmeals_loadswf_var = mealDetails.swf; > > > > > > > > >> > dispatchEvent(new > > > > > > Event('learnAboutThis', true)); > > > > > > > > >> > > > > > > > > > >> > } > > > > > > > > >> > > > > > > > > > >> > ]]> > > > > > > > > >> > </mx:Script> > > > > > > > > >> > > > > > > > > > >> > <mx:Image source="{'/uploads/nutrition/' + > > > > > > mealDetails.imgsource }" width="285" height="159"/> > > > > > > > > >> > > > > > > > > > >> > <mx:Label text="{mealDetails.serving}"/> > > > > > > > > >> > > > > > > > > > >> > <mx:Button label="Add to Meal" > > > > > > Event('addToMeal', true))"/> > > > > > > > > >> > > > > > > > > > >> > <mx:Button label="Learn About This" > > > > > > click="calldispatch()"/> > > > > > > > > >> > > > > > > > > > >> > </mx:Panel> > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > ------------------------------------ > > > > > > > > >> > > > > > > > > > >> > -- > > > > > > > > >> > Flexcoders Mailing List > > > > > > > > >> > FAQ: > > > > > > <http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt> yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > > > > > > > >> > Alternative FAQ location: > > > > > > > > > > > > https://share. <https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-> acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-\ \ > > \ > > > > \ > > > > > > 1e62079f6847 > > > > > > > > >> > Search Archives: > > > > > > http://www.mail- <http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo> archive.com/flexcoders%40yahoogroups.comYahoo! > > > > Groups > > > > > > Links > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > >> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ------------------------------------ > > > > > > > > > > > > > > > > > > -- > > > > > > > > > Flexcoders Mailing List > > > > > > > > > FAQ: > > > > > > <http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt> yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > > > > > > > > > Alternative FAQ location: > > > > > > > > > > > > https://share. <https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-> acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-\ \ > > \ > > > > \ > > > > > > 1e62079f6847 > > > > > > > > > Search Archives: > > > > > > http://www.mail- <http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo> archive.com/flexcoders%40yahoogroups.comYahoo! > > > > Groups > > > > > > Links > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
| Free embeddable forum powered by Nabble | Forum Help |