dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Help with AS3 & XML

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    2

    Help with AS3 & XML

    Hi,

    Im building a flash app to retrieve XML data which depends on what a user searches for.

    The following as3 code places an input field and submit button which allows a user to type in a postcode into the input box and click search and what should be returned in a list of all the properties that have that postcode.

    import fl.controls.Label;
    import fl.controls.TextInput;
    import fl.controls.Button;

    var postcodeLabel:Label = new Label();
    var postcodeTi:TextInput = new TextInput();
    var tf:TextFormat = new TextFormat();
    var submitBtn:Button = new Button();

    var xmlLoader:URLLoader = new URLLoader();
    var xmlData:XML = new XML();

    xmlLoader.addEventListener(Event.COMPLETE, LoadXML);

    xmlLoader.load(new URLRequest("http://www.kingsestateagents.com/site/go/api/search"));

    function LoadXML (e:Event):void
    {
    xmlData = new XML (e.target.data);
    }

    addChild(postcodeLabel);
    addChild(postcodeTi);
    addChild(submitBtn);

    tf.font = "Georgia";
    tf.color = 0x0000CC;
    tf.size = 16;

    postcodeLabel.text = "Postcode: "
    postcodeLabel.setSize(100, 25);
    postcodeLabel.move(90,100);
    postcodeLabel.setStyle("textFormat", tf);
    postcodeTi.move(160, 100);
    postcodeTi.setSize(200, 25);
    postcodeTi.setStyle("textFormat", tf);
    submitBtn.move(160,150);
    submitBtn.setSize(200, 25);
    submitBtn.label= "submit";

    submitBtn.addEventListener(MouseEvent.CLICK, Search);

    function Search(xml:XML):void
    {
    var propertyList:XMLList = xml.property.address.(postcode == postcodeTi.text);
    trace(propertyList.toString());
    }

    However, this doesn't seem to happen.
    Instead an error is returned.

    Ive never worked with flash and xml before so just taken the above xml bits from online websites but cant get it working.

    Just wondering whats wrong with it?

    Thank you!

  2. #2
    Member
    Join Date
    Mar 2004
    Location
    singapore
    Posts
    75
    Whats the error returned?

  3. #3
    Member
    Join Date
    Nov 2002
    Posts
    43
    Were do you get your xml parameter for Search function?
    Looks like it would be more logical to use Search(e:MouseEvent) and
    var propertyList:XMLList = xmlData.property.address.(postcode == postcodeTi.text);
    No?

    I didn't check all code, but this part looks very wrong.

    Do you use Flash or Flex?
    Last edited by olka_sb; 11-02-2009 at 05:32 PM.

  4. #4
    Member
    Join Date
    Nov 2002
    Posts
    43
    OK, I checked you code.
    It should work if you have your components in the library (Button, Label, TextInput), and change the code as I described in previous message.

  5. #5
    Junior Member
    Join Date
    Nov 2009
    Posts
    2
    Hi,

    thanks for your replies and ill be sure to try your code within half hour!

    The error i was getting was something like incorrect coercion cannot covert mouse event click to XML!

    Cheers!

    EDIT:

    Thanks for that!!

    Worked a treat indeed!

    No doubt ill be back with another problem

    Cheers!
    Last edited by eonmedia; 11-03-2009 at 04:46 AM.

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