A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: getting HTML source into Flash

  1. #1
    Junior Member
    Join Date
    Jan 2009
    Posts
    1

    getting HTML source into Flash

    This is a bit strange for me, as I was a Flash programmer until a few years ago, but I gave it up and got into other things. But now I'm starting a business and I'm trying to program something to help me save time.

    Basically what I want to do is this (and maybe Javascript is the best way, but I'd rather use Flash as I can generally remember how to use it):

    Send an HTTP request from Flash, and get the resulting HTML string into a variable into Flash, so I can break it down and analyse it.

    For example, you click a button and this request is sent:

    http://www.google.com/search?hl=en&c...oo&btnG=Search

    But the result does NOT open in a new window, instead the source code which would be rendered in another window comes back into Flash and is stored in a string.

    That's it! Seems simple on the face of it, but after spending a morning looking into it, now I'm not so sure.

    Just to clarify, I DON'T want to try to render this HTML in Flash, just get it back as a string that I can manipulate.

    If you want some of an idea of the context of this, here's an example. I want to run a search on ebay from Flash for an album by The Bees. I would use this search string:

    http://music.shop.ebay.co.uk/items/?...&_osacat=11233

    Then I would write some specific code to analyse the resulting string, and I would just extract the number of results, minimum price etc.

    Any help would be greatly appreciated

  2. #2
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    You can do it real simply like this with AS3:
    PHP Code:
    var page:String "http://www.google.com";
    var 
    loader:URLLoader = new URLLoader();
    loader.addEventListener(Event.COMPLETEonComplete);
    loader.load(new URLRequest(page));

    function 
    onComplete($e:Event):void
    {
        
    trace(loader.data);

    Now that's very basic, no load progress, no error handling, etc. It's parsed all as raw text right now, but if you wanted to get technical, you could throw it into the Flash XML engine by converting it to an XML object, but doing that, you're prone to all kinds of errors because most site's don't conform to XML standards like they should and it'll throw a TypeError. BUT, you can do a check if it parses as XML first, and if so, continue, if not, parse using a different engine.

  3. #3
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Here is the equivalent AS2 version:
    PHP Code:
    var page:String "http://www.google.com";
    var 
    loader:LoadVars = new LoadVars();
    loader.onData onComplete;
    loader.load(page);

    function 
    onComplete($data:String):Void
    {
        
    trace($data);


  4. #4
    Junior Member
    Join Date
    Jan 2009
    Posts
    1
    Hey,

    Thank you veeeery much I'm not really up with AS3, but it seems to make sense to me. I'll give it a go and tell you how it goes.

    Thanks again!

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