Nov 23

as3yaml – A YAML 1.1 parser and emitter for ActionScript 3

Tag: AS3, ActionScript, as3yaml, yamlDerek Wischusen @ 7:13 pm

I am pleased to announce the first release of as3yaml, an ActionScript 3 library for parsing and emitting YAML. It is a direct port of Ola Bini’s jvyaml, which was itself a port of Kirill Simonov’s PyYAML.

For those of you who are unfamiliar with YAML, here is a concise description from the yaml.org welcome page:

YAML(tm) (rhymes with “camel”) is a straightforward machine parsable data serialization format designed for human readability and interaction with scripting languages such as Perl and Python. YAML is optimized for data serialization, configuration settings, log files, Internet messaging and filtering. YAML(tm) is a balance of the following design goals:

  • YAML documents are very readable by humans.
  • YAML interacts well with scripting languages.
  • YAML uses host languages’ native data structures.
  • YAML has a consistent information model.
  • YAML enables stream-based processing.
  • YAML is expressive and extensible.
  • YAML is easy to implement.

Here are some example of YAML taken from the current version of the YAML spec:

american:
  - Boston Red Sox
  - Detroit Tigers
  - New York Yankees     

national:
  - New York Mets
  - Chicago Cubs
  - Atlanta Braves     

-
  name: Mark McGwire
  hr:   65
  avg:  0.278     

-
  name: Sammy Sosa
  hr:   63
  avg:  0.288

Here is an example of decoding a YAML string and converting it to ActionScript objects:

With the following YAML stored in a file called myYaml.yaml

  ---
  Date: 2001-11-23 15:03:17 -5
  User: ed
  Fatal:
    Unknown variable "bar"
  Stack:
    - file: TopClass.py
      line: 23
      code: |
        x = MoreObject("345\n")
    - file: MoreClass.py
      line: 58
      code: |-
        foo = bar

You can load then load the YAML and decode it as follows.

   public function loadYaml() : void 
   { 
       var loader : URLLoader =  new URLLoader(); 
       loader.load(new URLRequest('myYaml.yaml')); 
       loader.addEventListener(Event.COMPLETE, onYamlLoad); 
   } 
  public function onYamlLoad(event : Event) : void 
  { 
       var yamlMap : HashMap = YAML.decode(event.target.data) as HashMap; // returns a HashMap 
       trace(yamlMap.get("Date"));  // returns a Date object and prints: Fri Nov 23 15:03:17 GMT-0500 2001 
       trace(yamlMap.get("User"));  // returns a String and prints: ed 
       trace(yamlMap.get("Fatal")); // returns a String and prints: Unknown variable "bar" 
       trace(yamlMap.get("Stack")); // returns an Array and prints: [object HashMap],[object HashMap] 
       trace(yamlMap.get("Stack")[0].get("line"));  // returns an Int and prints: 23 
       trace(yamlMap.get("Stack")[0].get("code"));  // returns a String and prints: x = MoreObject("345\n")     
 
  }

There are some more examples available in the as3yaml docs.

I have been working on this for a little while now, and running it through various tests, so I think it is at a point where it is ready to be released into the wild. Please submit any bugs that you find to the issues list on the google project site. If you have any interest in contributing to the project, please let me know.

 THANKS:

  • Of course, special thanks to Ola Bini and Kirill Simonov for their excellent work on jvyaml and PyYaml, respectively.
  • I would also like to thank the as3commons project.  This library made the port from Java quite a bit easier than it might have been. 

17 Responses to “as3yaml – A YAML 1.1 parser and emitter for ActionScript 3”

  1. Bachir says:

    Hi Derek, great post and awsome work!
    I had bit of problem with getting it to work:
    I am using Flash CS3 so the first problem was in
    Serializer.as

    import mx.utils.StringUtil;
    this is a flex package so i had to change it to

    import com.adobe.utils.StringUtil;
    in order for it to find the class

    but now I get:
    Serializer.as line 139
    1061: Call to a possibly undefined method substitute through a reference with static type Class.

    it’s at this line:
    return StringUtil.substitute(this.anchorTemplate, [new int(this.lastAnchorId)]);

    please help I couldn’t find any “substitute” method in com.adobe.utils.StringUtil

    how can i get this to work?

    thanks alot for your help

  2. Derek Wischusen says:

    Hi Bachir,

    Well, you could try to find an open source library that contains that method, or you could write it yourself. It’s pretty straight-forward with regular expressions. This is essentially what you need.

    public function substitute(string: String, …args): String
    {
    return string = string.replace(/{(\d+)}/g, function(a,b,c,d):String{return args[b]});
    }

    Add some error checking and throw this in a utility class and you should be good to go.

  3. Bachir says:

    Thanks for the prompt response Derek.

    Ok I have downloaded Flex3_SDK packages and classes so it’s all good using the utils classes.

    Another interesting error I got is:

    VerifyError: Error #1107: The ABC data is corrupt, attempt to read out of bounds.
    at Function/http://adobe.com/AS3/2006/builtin::call()
    at org.as3yaml::Parser/parseStreamNext()
    at org.as3yaml::Parser/peekEvent()
    at org.as3yaml::Composer/composeNode()
    at org.as3yaml::Composer/composeDocument()
    at org.as3yaml::Composer/getNode()
    at org.as3yaml::BaseConstructor/getData()
    at org.as3yaml::YAML$/load()
    at org.as3yaml::YAML$/decode()
    at Example_fla::MainTimeline/onYamlLoad()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

    had a look around and bumped to this thread:
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=72&catid=616&threadid=1323788&enterthread=y

    I believe sooner or later it will happen to everyone.
    Note sure about the workaround.

    Any thoughts.

    thanks again for your time and great share of your work.

  4. Bachir says:

    Hi Derek after further research:
    I found :
    [..]
    it seems that error was being generated in response to an in-line event handler that was named in its in-line definition. I was able to resolve the issue by either defining the event listener function outside of the listener declaration OR by removing the function name from the in-line definition.
    [...]

    seems it’s a known issue:
    https://bugs.adobe.com/jira/browse/SDK-14054

    maybe that will help. (you’re probably aware of all that)
    but I thought I’d leave it to the expert.

    thanks

  5. Bachir says:

    to summarize this,
    I got it working if compiled in flex3 SDK, but when compiling using Flash CS3 IDE i keep getting this “ABC…” error.

    hopefully Adobe will get that sorted.
    thanks alot for as3yaml!

  6. Bachir says:

    hi Derek,

    I was wondering if it is an expected behavior for the flash player to freeze during parsing large yaml file. I have noticed this is happening when Yaml.decode is at work.

    even a looping preloader animation stops from playing until parsing is complete(about 10 seconds)

    Is there any tips or tricks to have get around this?
    please help only if you got some time.

    thx

  7. Steffen says:

    great library, nice to see an usage of the as3commons lib.

    greetings
    steffen

  8. Bachir says:

    Hi Derek just to confirm the last changes, for whoever is using the latest library, the use has changed since the decoding returns a Dictionary instead of a HashMap.

    so the use is:

    var yamlDict : Dictionary = YAML.decode(event.target.data) as Dictionary; // returns a Dictionary
    trace(yamlMap.Date); // returns a Date object and prints: Fri Nov 23 15:03:17 GMT-0500 2001
    trace(yamlMap.User); // returns a String and prints: ed
    trace(yamlMap.Fatal); // returns a String and prints: Unknown variable “bar”
    trace(yamlMap.Stack); // returns an Array and prints: [object Dictionary],[object Dictionary]
    trace(yamlMap.Stack[0].line); // returns an Int and prints: 23
    trace(yamlMap.Stack[0].code); // returns a String and prints: x = MoreObject(”345\n”)

    will wait for Derek to confirm.
    Thanks Derek for the performance in decoding is super fast now.

  9. Jonathan Spooner says:

    This would be awesome if it wasn’t dependent on the Flex library.

  10. Derek Wischusen says:

    Hey Jonathan –

    Just to be clear. as3yaml only uses some of the utilities that are found in the mx packages (Base64Decoder, etc). I suppose I could have rewritten these classes, but I don’t see any reason to since Flex is open source and is freely available.

  11. Derek Wischusen says:

    Hey Bachir,

    You are correct, and thank you for posting this info. Everyone should refer to:http://as3yaml.googlecode.com/svn/trunk/docs/org/as3yaml/YAML.html#decode()

  12. abhishek says:

    could u tell me how to use ffmpeg format or any other which gives me facility to convert uploaded video to flv from flex to rails folder.
    abhishekchess1@gmail.com

  13. ruby delevoper says:

    where I can use this library???

  14. storage.goodmix » Blog Archive » links for 2009-02-12 says:

    [...] flexonrails.net » as3yaml – A YAML 1.1 parser and emitter for ActionScript 3 (tags: actionscript a) [...]

  15. Joel Parker Henderson says:

    Can you provide a version that is not dependent on Flex? I know Flex is open source but there’s a certification issue involved– it would be much better for my group if there were a non-Flex version. Thanks for your consideration… and for your YAML work of course! Cheers!

  16. Jason Aunkst says:

    A non flex Yaml Loader/Emitter would rox.

  17. Serialization and Reflection with YAML - I am Rafael says:

    [...] a great parser and emitter coded in AS3 that you can download here and read more here. Unfortunately, I was only able to compile it using the Flex SDK, so I modified it a bit for Flash [...]

Leave a Reply

Valium without prescription uk
Viagra fast delivery
Brand name cialis
Buy viagra uk no prescription
Viagra discount coupons
Viagra 50 mg online without prescription
Cheap tramadol overnight delivery
Valium online pharmacy
Buy generic valium online
Phentermine online uk
Buy viagra uk online
Buy levitra online canada
Buy generic propecia uk
Buy xanax 2mg no prescription
Phentermine without a prescription
Overnight delivery viagra
Order xanax online
Buy xanax canada
Where to buy viagra online
Phentermine 37.5 wholesale
Tramadol no prescription overnight delivery
Xanax buy uk
Viagra online without prescription reviews
Tramadol cod delivery
Buy tramadol cod
Propecia uk prices
Buy levitra
Buy cialis brand
Tramadol without prescription
Tramadol free shipping
Buy viagra online uk no prescription
Low price viagra
Generic xanax
Where to buy cialis without prescription
Tramadol online overnight
Buying cialis online without a prescription
Authentic phentermine 37.5
Propecia 1mg generic
Buy pfizer viagra without prescription
Online valium without prescription
Buy xanax cheap online
Overnight tramadol no prescription
Viagra price canada
Phentermine purchase online
Cheap cialis pills
Levitra purchase

Buy phentermine no script
10mg valium effects
Tramadol for sale
Valium from india
Buy viagra australia
Viagra cheap no prescription
Order tramadol cod
Generic viagra for sale
Buy viagra in england
Viagra discount prices
Valium pill 10mg
Viagra super active
Levitra online buy
Viagra shop online
Cheap viagra online without prescription
Propecia generic canada
Buy phentermine online without prescription
100mg tramadol online
Cheap cialis india
Viagra buy online no prescription
Buy phentermine 37.5mg pills
Tramadol india
Cialis order canada
Cialis dosage 20mg
Phentermine canada no prescription
Viagra prescription
Viagra pharmacy uk
Buying xanax online without prescription
Best price cialis
Canada viagra no prescription
Phentermine buy australia
Viagra to buy
Order prednisone no prescription
Buy viagra 100mg
Where can i buy viagra in the uk
40 mg prednisone side effects
Buy cialis uk
Cheap generic viagra
Viagra canada prices
Viagra online shop
Viagra pharmacy prices
Propecia generic online
Viagra online uk
Phentermine diet pills without prescription
Viagra india price
Valium drug side effects
Purchase phentermine online
Buy viagra online in australia
Generic cialis uk
Buy phentermine hcl 37.5 no prescription
Cheap tramadol cod
Prescription valium
Purchase phentermine without prescription
Propecia price
Buy female viagra without prescription
Buy valium cheap online
Viagra ordering
Viagra pills for sale
Prednisone dosages
Buying levitra without prescription
Buying prednisone online
Prescriptions for phentermine
2.5mg cialis
Generic cialis tadalafil
Xanax price per pill
Fedex tramadol
Canada pharmacy valium
Buy propecia
Cheap phentermine without prescription
Buy generic xanax no prescription
Buy valium without prescription uk
Levitra samples
Best way to take tramadol
Order tramadol online cod
Buy cheap valium online
Cheapest online cialis
Viagra generic cheap
Cialis cialis
Tramadol medication
Buy xanax overnight
Valium online fast delivery
Valium no rx
Xanax 1mg
Purchase viagra online without prescription
Viagra no prescription online
Prescription propecia
Generic tramadol
Generic viagra sales
Xanax for sale without prescription
Genuine viagra online
Cheap cialis viagra
Free samples of cialis
Generic cialis overnight
Where to buy cialis online
Xanax overnight cod
Cheap valium online
Phentermine 37.5mg
Viagra in france
Cost of viagra 50mg
Cheap 37 5 phentermine
Xanax no prescription required
Cialis 10mg side effects
Valium online uk
Viagra prescription cost
Levitra on sale
Cialis purchase online
Canada viagra
Xanax bars side effects
Discount viagra india
Cialis side effects
Real phentermine without prescription
Side effects of viagra
Cialis 20 mg dosage
Cheap levitra uk
Buy cialis online from canada
Where to buy phentermine cheap
Cheap 100mg viagra
Xanax bars dosage
Buy generic cialis
Prednisone 20mg side effects
Buy tramadol hcl
Australia viagra online
Phentermine buy uk
Prednisone online
Best price on phentermine
Online prescriptions xanax
Valium online overnight
Buying tramadol in uk
Viagra online cheap
Phentermine 37.5 buy online
Order tramadol overnight
Buy generic valium
Cialis online canadian pharmacy
Prescription free viagra
Levitra us
Buy brand name viagra
Viagra professional online
Tramadol pharmacy
Buy viagra from canada
2mg xanax no prescription
Buy phentermine 37.5mg online
Propecia generic cost
Pharmacy tramadol
Tramadol dosage
Order cheap phentermine
Xanax no prescription overnight
100mg tramadol effects
Dose of xanax
Propecia information
Cialis price
Cheapest cialis price
Mail order phentermine
Generic viagra super active
Cheap generic valium
Australia viagra prescription
Propecia price australia
Cheapest cialis professional
Best prices for cialis
Xanax with no prescription
Cialis prices uk
Purchase levitra online
Purchase tramadol without prescription
Buying cialis
Phentermine 37.5 pills
Cheap cialis soft tabs
Discount viagra usa
Xanax bars effects
Cialis for sale
How to buy valium without a prescription
Cheap levitra no prescription
Levitra price
Viagra indian pharmacy
Generic propecia
Buying viagra online
Drug phentermine
Best way to buy viagra online
Viagra for sale online
Brand viagra cheap
Propecia cheap
Purchase phentermine
Prescription phentermine online
Pfizer viagra price
Cialis prescription cost
Phentermine cheap online
Prescription viagra uk
Viagra express delivery
Xanax online cheap
Levitra online
Buy propecia cheap
Where can i buy viagra without prescription
Buy viagra in canada online
Buy viagra online cheap
Viagra online purchase in india
Order cheap viagra online
Where can i buy cialis without a prescription
Generic viagra 100mg
Phentermine online free shipping
Buy tramadol hydrochloride
Xanax 1 mg dose
Discount viagra pills
Where to buy levitra online
Phentermine hcl without prescription
Buy propecia online without a prescription