IAB VAST ActionScript 3 Library

As a personal project, I wanted to put together a parser for VAST responses. So I created an ActionScript library on GitHub. It’s basic but takes care of the monotonous XML to AS3 mappings. It also allows for custom extension parsers.

For more info, visit the project page: http://nathanhinish.github.com/AS3-IABLib/

UPDATE: I think a WP update borked the page. If there’s interest I’ll put it up. Otherwise, here’s the link to the GitHub repo. https://github.com/nathanhinish/AS3-IABLib

UPDATE #2: There is growing interest in the library so I wanted to make sure the documentation is available online. To that end, I created a GitHub project page that has a link to the documentation. http://nathanhinish.github.com/AS3-IABLib/

16 thoughts on “IAB VAST ActionScript 3 Library

    • Hi Siri,

      Sorry for the delay. I actually had a bug in the code. (a couple in fact) I just updated the project on GitHub so if you pull the latest changes, you should have your code working. Again, sorry about that.

      Nate

  1. Hi Nathan,

    I am implementing VAST into our player, thanks for your library.
    I have a question
    I am working with this sample
    http://ad3.liverail.com/?LR_PUBLISHER_ID=1331&LR_CAMPAIGN_ID=229&LR_SCHEMA=vast2
    and try to access the Impression tags

    I tried that but does not seem to work maybe the syntax is wrong
    trace(output1.ads[0].InLine.Impression)

    also can I use the embed tag and replace the path to an url ?
    [Embed(source = "../../../../../resources/vast_sample_1.xml", mimeType = "application/octet-stream")]

    [Embed(source = "http://test.xml", mimeType = "application/octet-stream")]
    I tried but I have an error

    Thank you

    • Hey Lea,

      Glad to hear people are actually using this library. :)

      So to answer your first question, the parsed structure isn’t exactly one-to-one with the XML structure. I actually have an InLine class extending the Ad class. So the way to query this would be like so: output1.ads[0].impressions. There shouldn’t be that extra .InLine in the code.

      As for using embedded XML, that should definitely be acceptable. It’s just looking for an XML object. Using the method you mention in your post, keep in mind that when you embed using octet-stream, the associated class is going to be a byte array. So you’ll need to do something like this…

      [Embed(source = "text.xml", mimeType = "application/octet-stream")]
      private var XML_C:Class;

      var x:ByteArray = new XML_C();
      var s:String = x.readMultiByte(x.bytesAvailable, "utf-8");
      var content:XML = XML(s);
      var p:VASTParser = new VASTParser();
      p.setData(content);
      var v:VAST = p.parse();

      But you can’t use the Embed method for URLs, which is what I think you’re asking. In order to use a URL, you’ll have to use something like this…


      private static const URL:String="http://ad3.liverail.com/?LR_PUBLISHER_ID=1331&LR_CAMPAIGN_ID=229&LR_SCHEMA=vast2";
      private var _l:URLLoader = new URLLoader();
      _l.addEventListener(Event.COMPLETE, onComplete);
      _l.load(new URLRequest(URL));
      private function onComplete(event:Event):void
      {
      var content:XML = XML(_l.data);
      var p:VASTParser = new VASTParser();
      p.setData(content);
      var v:VAST = p.parse();
      trace(v);
      }

      If that doesn’t solve your problem, let me know and we’ll try to figure out what’s going on. :)

      • Thanks a lot Nathan !
        Everything is working perfect
        I have one more question for you I have some difficulties to access the MediaFile node

        //MediaFile
        trace(String(v.ads[0].creatives[0].mediafiles[0]))

        I am sure I am missing something on this one too
        Thanks for your help

        • This one is actually pretty close. If you look at the documentation for the Creative class, you’ll see a ‘source’ property. Since a creative can have either a Linear, an array of CompanionAds, or an array of NonLinearAds, this had to be kind of generic. But to answer your question, I believe if you try v.ads[0].creatives[0].source.mediaFiles[0], you should be able to get access to your media file. Better yet, I’d actually do a type check first…

          if(v.ads[0].creatives[0].source is Linear)
          {
          trace(v.ads[0].creatives[0].source.mediaFiles[0]);
          }

          I suggest this because neither the CompanionAds nor the NonLinearAds classes have the mediaFiles property and would cause that line to throw an error.

  2. Thanks Nathan !

    I am almost done with getting all the datas from the xml file
    Here is my final function

    http://pastebin.com/q99fKu73

    I still have some questions if you have time

    Did you ever get error ?
    its happening for this line
    if(v.ads[0].creatives[0].source is Linear)
    {
    RangeError: Error #1125: The index 0 is out of range 0.
    at com.vidplayer::Moogaloop/onComplete()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

    Here is the xml that i am testing : http://ad.doubleclick.net/pfadx/N270.132652.1516607168321/B3442378.3;dcadv=1379578;sz=0×0;ord=79879;dcmt=text/xml

    Thanks

    • That error is saying that the vector/array doesn’t include the index you are trying to access. In your case either ads or creatives has a length of zero. (that’s the range 0 part of the error message) However, when I test your URL, I am not getting that error. If it happens all the time, I’m not sure what’s going on. If it only happens sometimes, my guess is that the same content isn’t being returned each time. You could expand your conditional to check each array for the proper length. Like this…

      if (v.ads.length > 0 && v.ads[0].creatives.length > 0 && v.ads[0].creatives[0].source is Linear)

      I know that’s a little long, but that will check to make sure each of the vectors is populated with the proper data. Also, it may be important for you to know that the Linear ad doesn’t always come first. So it could be one of the other elements in the creatives vector that refers to the Linear ad.

      Hope that helps.

      Nate

  3. Hi Nathan,

    Me again,
    The vast implementation works perfectly thanks to your parser.
    Now my company want our players to be VPAID complaint , but I am very confused since i am looking for a lot of video related event ( PLAY / PAUSE / SEEK etc … ) right now i was looking for loading a flv or mp4 file.
    They want to be able now to load a swf file.
    Can you help to understand how to implement that ?
    Are you available to chat via aim ?
    Thanks
    Lea

    • Hi Axel,

      The MediaFile class extends the URIIdentifier class. This class has a ‘uri’ attribute. So you just need to add that to the end of your code.

      v.ads[0].creatives[0].source.mediaFiles[0].uri

      Hope that helps.

      • Thanks so much for your response…I hadn’t seen it till after I posted my second question… I actually had figured out uri…but now the title is driving me nuts. Thank you so much.

Proudly powered by WordPress
Theme: Esquire by Matthew Buchanan.