Welcome, Guest
  • Author Topic: select combobox value from mysql result?  (Read 13608 times)

    jarmanje

    • Senior Programmer
    • ****
    • Posts: 334
      • View Profile
    select combobox value from mysql result?
    « on: 09/26/08, 18:54 »
    Hello. How can i fill a combobox based on the value of a var. Jorge previously helped me do it with a DateField.

    This is what i'm trying to do, but this code is all wrong:

    Code: [Select]
    <mx:ComboBox editable="false" enabled="true"><mx:ArrayCollection>
                     <mx:Object label="Main stage" data="stage1"/>
             <mx:Object label="2nd stage" data="stage2"/>
             <mx:Object label="3rd stage" data="stage3"/>
          </mx:ArrayCollection>

    Currenctlyselected value of combox = callfunctioninas3();
    </mx:ComboBox>



    //code in <!CDATA{

    private function callfunctioninas3():void
    {
    if (currentOrder.order=="stage1") {
    //set value of combox to "Main stage"
    } else if (currentOrder.order=="stage2") {
    //set value of combox to "2nd stage"
    } else if (currentOrder.order=="stage3") {
    //set value of combox to "3rd stage"
    } else {
    //set the combox to nothing
    }
    }
    Sorry for my amateur coding, but it shows how i'd like to do it!

    Thanks a lot for any help

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: select combobox value from mysql result?
    « Reply #1 on: 09/27/08, 09:26 »
    For this kind of apps the best is to use DTO (Data Transfer Objects), that are basically data containers, simple classes with bindable and public values that you use to bind everywhere on your interface. This way you take the fully potential of Flex, no keeping track manually of each component data manipulation.
    Here's an example of DTO used for the Datefield example in the other POST


    package com
    .flashdb.dto
    {
    	
    	

    	
    [
    Bindable]
    	
    public class 
    room extends Object
    	
    {
    	
    	
    public var 
    name:String;
    	

    	
    	
    public var 
    date:String;
    	
    	
    public var 
    duration:Number;
    	

    	
    	
    public var 
    comment:String;
    	
    	
    public var 
    status:Number
    	
    	

    	
    	
    public function 
    room(obj:Object){
    	
    	
    	
    if(
    obj.namename obj.name
    	
    	
    	

    	
    	
    	
    if(
    obj.datedate obj.date
    	
    	
    	
    if(
    obj.durationduration obj.duration
    	
    	
    	
    if(
    obj.commentcomment obj.comment
    	
    	

    	
    	
    	
    if(
    obj.statusstatusobj.status
    	

    	
    	
    }
    	
    }
    }


    The class is just a container, the important thing is to have all public properties and the Bindable thing. Then in the mxml you use:

    import com.flashdb.dto.room;
    ....
    course = new Course({})   

    And finally in any component you can bind as {course.Title} in example.
    This is the key of taking the full power of Flex

    I have a tutorial almost ready to ilustrate this, hope to publish it this week

    Jorge

    jarmanje

    • Senior Programmer
    • ****
    • Posts: 334
      • View Profile
    Re: select combobox value from mysql result?
    « Reply #2 on: 09/28/08, 05:29 »
    thanks so much for the detailed reply

    I'm going to try it in the office on monday.
    thanks again

    jarmanje

    • Senior Programmer
    • ****
    • Posts: 334
      • View Profile
    Re: select combobox value from mysql result?
    « Reply #3 on: 09/28/08, 11:01 »
    Hi Jorge, I have been having a go at your code. I think I understand how it is working, but I have never used such a setup and having some problems.

    I have in one folder OrderForm.mxml and inside the same folder DTO.as

    my DTO.as is this
    Code: [Select]
    package forms.DTO
    {
    [Bindable]
    public class room extends Object
    {
    public var date:String;
    public var status:Number

    public function room(obj:Object){
    if(currentOrder.date) date = currentOrder.date
    if(currentOrder.status) status= currentOrder.status
    }
    }
    }

    inside OrderForm.mxml i have this:
    Code: [Select]
    <mx:Script>
    <![CDATA[
    import events.OrderEvent;
    import forms.DTO.room

    [Bindable]

    public var currentOrder:Object = new Object();


    private function saveRecord():void
    {
    //var order:Object = new Object();
    //order.orderid = currentOrder.orderid;
    //order.status = statusInput.text;
    //order.email = emailInput.text;
    //var e:OrderEvent = new OrderEvent("save", order);
    //dispatchEvent(e);
    }
    private function cancel():void
    {
    currentOrder = new Object();
    dispatchEvent(new Event("cancel"));
    }
    ]]>
    </mx:Script>

    <mx:DateField id = "orderdate" formatString="YYYY-MM-DD" width="170" showToday="true" text ="{course.Title}"/>

    My two questions are, What is the {course.Title} ? Should this be in my case "{currentOrder.date} ?

    Also, I have an error:

    1172: Definition forms.DTO:room could not be found.   adman2/src/forms   OrderForm.mxml

    I realise I have placed something wrong, but have tried placing it everywhere.

    Thanks again for this, it looks like once I understand this part it will be so easy to handle data in the whole app..
    « Last Edit: 09/28/08, 11:09 by jarmanje »

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: select combobox value from mysql result?
    « Reply #4 on: 09/28/08, 12:04 »
    You should use:

    public var currentOrder:room= new room();

    and your binds should be of course

    {currentOrder.date} or {currentOrder.status}

    Anyway use a class name and properties related to your goals, room is just related to my example

    Jorge

    jarmanje

    • Senior Programmer
    • ****
    • Posts: 334
      • View Profile
    Re: select combobox value from mysql result?
    « Reply #5 on: 09/28/08, 12:28 »
    Hi Jorge,

    Thanks for the reply. I understand what I should be doing. but something is wrong.

    I cannot import the class! It is the correct syntax because flex even finishes the sentece for me

    import forms.DTO.orderInfo

    There is no problem with import forms.DTO, but it still does not find my function called orderInfo.

    Is my class 100% correct?

    Code: [Select]
    package forms.DTO
    {

    [Bindable]
    public class orderInfo extends Object
    {
    public var date:String;
    public var status:Number

    public function orderInfo(obj:Object){
    if(currentOrder.date) date = currentOrder.date
    if(currentOrder.status) status= currentOrder.status
    }
    }
    }

    1172: Definition forms.DTO:orderInfo could not be found.   adman2/src/forms   OrderForm.mxml   line 14   1222623082576   312
    « Last Edit: 09/28/08, 12:31 by jarmanje »

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: select combobox value from mysql result?
    « Reply #6 on: 09/28/08, 13:44 »
    Look for misspellingsm, typos, paths, etc. Change the name of your class is needed. Check that you have your class inside folder src/forms/DTO, etc

    Jorge

    jarmanje

    • Senior Programmer
    • ****
    • Posts: 334
      • View Profile
    Re: select combobox value from mysql result?
    « Reply #7 on: 09/28/08, 14:06 »
    It's crazy

    Import forms.DTO;  has no errors.

    but Import forms.DTO.orderInfo;  says it calls a possibly undefined method orderInfo

    but orderInfo is 100% correctly in there?!?

    it is perfectly matched to your example? Am i blind?

    Code: [Select]
    package forms.DTO
    {

    [Bindable]
    public class orderInfo extends Object
    {
    public var date:String;
    public var status:Number

    public function orderInfo(obj:Object){
    if(obj.date) date = obj.date
    if(obj.status) status= obj.status
    }
    }
    }

    jarmanje

    • Senior Programmer
    • ****
    • Posts: 334
      • View Profile
    Re: select combobox value from mysql result?
    « Reply #8 on: 09/29/08, 07:01 »
    Hi jorge,

    would it be possible for me to look at your work in progress tutorial example file?

    I'm at an absolute loss as to why the function can not be called.

    Do i save it as a DTO.as  ???

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: select combobox value from mysql result?
    « Reply #9 on: 09/29/08, 07:06 »
    The fails is at a basic level:

    1. Create a class
    2. Import to your mxml
    3. Instantiate it

    This is not related to DTO by any means, but at the ABC of coding.
    Then specific to your code, pass an empty objetct in the constructor or declare a default in your DTO constructor argument, that means instantiate like this:

    var myOrder:orderInfo = new orderInfo({})

    of in orderInfo constructor:

    public function orderInfo(obj:Object = null)

    Jorge

    jarmanje

    • Senior Programmer
    • ****
    • Posts: 334
      • View Profile
    Re: select combobox value from mysql result?
    « Reply #10 on: 09/29/08, 09:07 »
    ok now I am getting closer! I have done step 1 and 2. I created a new class from file -> new class and it worked with a different name...

    here is how it looks in my mxml (i've renamed class to 'orders', and the function inside it is called orders):
    Code: [Select]
    import forms.orders.orders

    [Bindable]
    public var Myorder:orders= new orders({});
    public function orders(currentOrder:Object = null);

    There is an error with the last line. 1126: Function does not have a body.

    But it does... seems a perfect function to me

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: select combobox value from mysql result?
    « Reply #11 on: 09/29/08, 09:16 »
    What the purpose of this method? (with the same signature as the orders contructor)

    public function orders(currentOrder:Object = null);

    Jorge

    jarmanje

    • Senior Programmer
    • ****
    • Posts: 334
      • View Profile
    Re: select combobox value from mysql result?
    « Reply #12 on: 09/29/08, 09:36 »
    The purpose is for the combobox and dataField problem. my problem is I need to use your method, because without it, I have errors when creating a NEW order. the orderField requires some input.

    I made the class, called orders.as
    Code: [Select]
    package forms.orders
    {

    [Bindable]
    public class orders extends Object
    {
    public var date:String;
    public var status:Number

    public function orders(obj:Object){
    if(currentOrder.date) date = currentOrder.date
    if(currentOrder.status) status= currentOrder.status
    }
    }
    }

    i then import to my mxml
    Code: [Select]
    import forms.orders.orders
    I try to instantiate it:
    Code: [Select]
    [Bindable]
    public var Myorder:orders= new orders({});
    public function orders(currentOrder:Object = null);

    i use the data source in my DateField:
    Code: [Select]
    <mx:DateField id = "orderdate" formatString="YYYY-MM-DD" showToday="true" text ="{orders.date}"/>



    I think I almost have your DS method working, but the line
    Code: [Select]
    public function orders(currentOrder:Object = null);gives me such an error:

    1126: Function does not have a body.   adman2/src   ModifyData.mxml


    I apologise I realise I am being annoying. I'm learning flex and the DS looks good but i can't get it to work. I'd like to start to use DS


    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: select combobox value from mysql result?
    « Reply #13 on: 09/29/08, 09:39 »
    Ok, don't understand this line

    public function orders(currentOrder:Object = null);

    So just delete it, make no sense. If you get Binding warnings just leave it, you get it usuallyt when the DTO is filled at runtime

    Jorge

    jarmanje

    • Senior Programmer
    • ****
    • Posts: 334
      • View Profile
    Re: select combobox value from mysql result?
    « Reply #14 on: 09/29/08, 09:52 »
    Hi Jorge,
    I was just trying to follow your previous post. I think i got confused?
    Then specific to your code, pass an empty objetct in the constructor or declare a default in your DTO constructor argument, that means instantiate like this:

    var myOrder:orderInfo = new orderInfo({})

    of in orderInfo constructor:

    public function orderInfo(obj:Object = null)

    I've removed that line and now i get 2 new errors with the public var line. I'm going to spend a few hours trying to fix it, i suppose it's just basic stuff i dont know yet..