A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: data bindings with just code?

  1. #1

    data bindings with just code?

    Hi,

    I have started using the the xmlConnector and data bindings in MX PRO 2004, but am frustrated at the lack of documentation on how to bind during runtime. Most of the apps I build are pretty big and I'm wondering if anyone has had success binding data from the xmlConnectors result to another component using just code?

    Most of the time im loading xml in and then creating a dataProvider for a component. Is there a way to do this with the xmlConnector and bindings using just code?

    any help would be much appreciated.

    thanks

    gmc

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141

  3. #3
    Senior Member
    Join Date
    May 2002
    Location
    The Great Northwest
    Posts
    380
    That link doesn't show you how to do databinding with code. It only shows the GUI way. I have been searching for similar information and the only thing I could find is in the Flash Documentation. You have to use the EndPoint class and the DataBinding class. I haven't gotten it to work with their examples. It would be nice if there was a better example out there.

    I haven't seen one yet, but I am always looking.
    God bless you!

  4. #4
    Hi guys,

    I have asked around and nobody knows how to do this so I have started a poll which I will after a week or two send the link to macromedia and see what they think.

    check it out and please add your comments so we can get a tutorial on this interesting subject.

    http://www.flashkit.com/board/showth...hreadid=504552

    thanks,

    gmc

  5. #5
    Senior Member
    Join Date
    May 2002
    Location
    The Great Northwest
    Posts
    380

    Foud out what I was missing.

    You need to be sure to include the DataBindingClasses from the

    Windows > Other Panels > Common Libraries > Classes

    If you include this in your movie then you can use the EndPoint class with the Binding class to create the relationship.

    Macromedia's code from the help file:

    If you use two of the inputText COMPONENTS and drag them to your screen you name one src_txt and the other dest_txt you will be able to see the wonders of data binding with only code. Be sure to include the DataBindingClasses compiled clip from the library!

    Code:
    import mx.data.binding.*;
    var src = new EndPoint();
    src.component = src_txt;
    src.property = "text";
    src.event = "focusOut";
    
    var dest= new EndPoint();
    dest.component = dest_txt;
    dest.property = "text";
    
    new Binding(src, dest);
    God bless you!

  6. #6
    Hi GreatGatsby,

    Glad to hear you were able to get the example to work. I have also done the same example, but it's pretty simple compared to binding a the results from the xmlConnector to the dataProvider of another component.

    I can't find any documentation on how I can do that, which is a bit odd seeing that's what most developers are doing?

    If you have any ideas on how to do that then please let me,

    Cheers,

    gmc

  7. #7
    Senior Member
    Join Date
    May 2002
    Location
    The Great Northwest
    Posts
    380

    I thought you would ask.

    I am working on an example right now. Will let you know if I get anything
    God bless you!

  8. #8
    Senior Member
    Join Date
    May 2002
    Location
    The Great Northwest
    Posts
    380

    A little closer...

    Wow this is getting to be fun!

    Here we go so far...

    I placed a dataSet on the stage (data_ds);
    I placed a dataGrid on the stage (grid_grd);
    I placed an XMLConnector on the stage (xml_con);

    I linked xml_con to my Hello.xml file which looks like this:

    < hello>
    < message>
    < id>1< /id>
    < body>Hello Databinding!< /body>
    < date>10/23/2003< /date>
    < /message>
    < message>
    < id>2< /id>
    < body>ActionScript 2.0 rocks!< /body>
    < date>10/24/2003< /date>
    < /message>
    < /hello>


    I established a Databinding from data_ds to grid_grd through the Component Inspector Panel. However I did not establish a connection from xml_con to data_ds through the panel. I did that through the code below.

    Code:
    import mx.data.binding.*;
    
    var src = new EndPoint();
    var dest = new EndPoint();
    
    src.component = xml_con;
    src.property = "results";
    src.location = "hello.message";
    src.event = "result";
    
    dest.component = data_ds;
    dest.property = "dataProvider";
    
    new Binding(src, dest);
    
    xml_con.trigger();
    The key to making this work is in the location EndPoint. and subscribing to the correct event. I look at the events for the XMLConnector in help files. result is the one that broadcasts once a result has been validated. As you can see I am linking it to the dataProvider property of my data_ds component. This is not a 100% answer, but it is a lot closer. I was having problems linking attributes of my message tag inside of my xml document. Although the correct header would display the actual data wasn't linked. I believe this to be something with the location of my EndPoint. I could have dynamically attach the data_grd and the data_ds and linked them that way. I just wanted a quick illustration. I hope this helps you get closer. I am done for the night, but I will be digging deeper into this during the week.
    God bless you!

  9. #9
    Hi GreatGatsby,

    great work! We are a little bit closer but not quite there yet. I have tried setting the data binding from the xmlConnector's results to a dataHolder component but it seems to bind the data just as xml and not a dataProvider. I have tried adding formatters to the bind but it doesn't seem to work?

    Also just noticed that you can use xPath expressions for the src.location eg. "/hello/message";

    I have a site due at the end of the week so am going to use flashMX for the mo, but will keep experimenting in flash MX Pro 2004. Let me know how you get on.

    gmc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center