Flash Player 8.5 Alpha and GIS

This weekend i continued to play with Flash Player 8.5 alpha, and did something kinda crazy (at least i thought so when i started).. I tried to render high resolution GIS data purely clientside with Flash.

In the beginning, i was just searching for detailed, free, redistributable map data of the world, with political country boundaries, and maybe state boundaries too, to write a simple world map component. I was scanning through a lot of link lists, and almost all material i found was either incomplete, not detailed enough or expensive. Except the “Vector Smart Map Level 0 Library”, a huge (1.8GB), free and redistributable collection of all sorts of high detailed geographic data, published by the National Imagery and Mapping Agency (NIMA).

“Published by the National Imagery and Mapping Agency (NIMA) on CD-ROM, the VMap0 database is designed to provide vector-based geospatial data at low resolution. The content of the database is similar to the previously published Digital Chart of the World, augmented with low resolution bathymetry for global coverage. A reference library with general information to orient the user and an index of geographic names to aid in locating areas of interest are provided. Data are separated into thematic layers: boundaries, elevation, hydrography, industry, physiography, population, transportation, utilities, and vegetation.

VMap0’s world coverage is divided into four libraries based on geographic areas. The geographic areas and library names, by disc, are:

* Disc 1 – North America (NOAMER)
* Disc 2 – Europe and North Asia (EURNASIA)
* Disc 3 – South America, Africa, and Antarctic (SOAMAFR)
* Disc 4 – South Asia and Australia (SASAUS)

The primary source for the database is the 1:1,000,000-scale Operation Navigation Chart (ONC) series co-produced by the military mapping authorities of Australia, Canada, United Kingdom, and the United States. Data gaps may exist where source information is not available.”

But how to get this data into the Flash Player? The format they use is VPF (Vector Product Format, [PDF]), a heavily cross linked, binary format. I started reading through the spec, and thought that with the capabilities of the new Flash Player 8.5 alpha (highly increased VM performance), it could actually work to just load the data as is and render it. Said and done.

Here’s a proof of concept application i threw together over the weekend, that loads the “Library Reference” coverage (3MB, binary, as is, using the new URLStream class), deserializes the data into Arrays, and renders the data on screen while loading. What we get is a quite detailed map of the world with country-level political boundaries.

http://codeazur.com.br/stuff/flex2/vmap0/
Note: Flash Player 8.5 alpha required! (Get it here)

For those of you who don’t have the alpha player installed, here is a screenshot:
Vector map of the world, global view

And here’s another, fully zoomed in to Japan:
Vector map of the world, Japan (zoomed)

The Flash Player renders the whole map in around 5 seconds (delayed with enterframe events) on my machine, drawing 250.000 lines in more than 2.000 shapes.

The only drawback: it takes a while until the data is loaded (depends on your connectivity of course).

FP 8.5: Tooltips over links in HTML enabled TextFields

If you move your mouse pointer over a hyperlink in an HTML webpage, your browser typically displays the URL in it’s status bar. In addition, if the hyperlink has a title attribute set, a tooltip is shown with a human readable description of the linked resource.

Unfortunately, with rich text used in Flash websites/applications this is not the case. Your mouse pointer will change to a “hand-cursor”, indicating you’re hovering a hyperlink, but the status bar will stay empty, and the title attribute is ignored by Flash, making it impossible for you to find out where the hyperlink will take you without actually clicking it.

With Flash Player 8.5 alpha, the behaviour of hyperlinks in rich text controls hasn’t changed (yet?), but luckily Macromedia implemented some nifty API extensions making it possible to actually find out if the user is hovering a hyperlink in a HTML enabled TextField.

Here’s how it works:

FP 8.5 introduces the TextField.getCharIndexAtPoint(x, y) method, returning the index of the character in a TextField at the point (x, y).

You can then get the TextFormat of the character at that index, using TextField.getTextFormat(i, i+1), and check it’s url property. If set, display it in a Tooltip, or send it to Javascript via ExternalInterface to show it in the browser’s status bar. Done.

Demo:

http://codeazur.com.br/stuff/flex2/OnHoverApp.html (FP 8.5 required)
http://codeazur.com.br/stuff/flex2/OnHoverApp.zip (Sources)

In this demo i subclassed the Flex 2 component mx.controls.Text and use it via MXML, however you can as well use this method with normal TextFields in your Actionscript 3 projects.

Flash Player 8.5 – SPEED!

You heard the news already, Macromedia launched their Labs site today, along with public alphas of Flash Player 8.5, Flex Builder 2 and the Flex Framework 2.

Among the first things i did with those alpha goodies was porting the DENG CSS 3 parser to Actionscript 3.

Results of first benchmark (Parsing a 20kb CSS file into an object DOM):

  • AS2, Flash Player 8: around 1000ms
  • AS3, Flash Player 8.5: around 80ms

That’s a 12.5x performance boost, without FP8.5 specific optimizations.
Flash is fun again!

I’m going to prepare a live demo of the parser in the next days for you to play with it.

XFrames: New Working Draft published today

The W3C published a new working draft of their XFrames specification today, an XML application designed to replace HTML Frames.

XFrames solves most usability problems known from HTML Frames (Back button, bookmarking, page reloads, search engine woes, etc) by introducing a new URI reference notation:

http://example.org/home.xframes#frames(id1=uri1,id2=uri2,...)

In addition to vertically and horizontally tiled frames, XFrames introduces two new composition modes “single” (one frame visible at a time, navigation through tabs, for example) and “free” (movable, overlapping windows), making it an extremely simple but powerful tool for web application development.

DENG 1.0 already features an experimental XFrames implementation, and even better support for the latest spec is one of the priorities for DENG 2.0.

DENG 2.0 Roadmap (first draft)

Macromedia announced the Flash Player 8.5 today, featuring a completely new virtual machine (AVM2), E4X, RegExp, Binary Sockets and W3C DOM Events.

Flash Player 8.5 (along with the Flex 2 Framework and Flex Builder 2) will be released as public alpha on October 17th.

This marks the beginning of the development of DENG 2.0, a completely refactored DENG version targeted for Flash Player 8.5 and above.

Features i plan for DENG 2.0 (incomplete, vague, and subject to change, just to give you a rough overview):

  • Improved performance
  • Flex 2.0 Integration, targeted for AVM2
  • 100% compliant CSS 3 parser
  • Compliant implementations of SVG-T, XForms 1.1
  • Better support for XHTML, SMIL, XFrames etc.
  • Support for subsets of XUL
  • Support for W3C DOM
  • Better CSS box model implementation (DENG currently doesn’t support absolute/relative positioning and inline-boxes, the tables implementation is not perfect, etc.)
  • Better CSS line box model implementation (DENG uses the native TextField object of the Flash Player to render inline text. This won’t change, but improvements in the Flash Player since version 6 allow some more sophisticated features (e.g. a:hover, left/right floats).
  • GIF, PNG and SVG images (DENG currently supports JPEG only), background images

CSS 3 modules and envisioned compliance:

  • Syntax/Grammar (full)
  • Selectors (full)
  • Values and Units (full)
  • Value Assignment, Cascade, Inheritance (full)
  • Box Model, Vertical (as full as possible)
  • Positioning (as full as possible)
  • Color, Gamma, Color Profiles (partial)
  • Colors and Backgrounds (full)
  • Line Box Model (partial)
  • Text (partial)
  • Fonts (partial)
  • Ruby (none)
  • Generated Content, Markers (as full as possible)
  • Replaced Content (as full as possible)
  • Paged media (as full as possible)
  • User interface (as full as possible)
  • WebFonts (partial)
  • ACSS (none)
  • SMIL (as full as possible)
  • Tables (partial)
  • Columns (partial)
  • SVG (as full as possible)
  • Math (partial)
  • BECSS (none)
  • Media queries (as full as possible)

Stay tuned.

New DENG Build: 1.0.43

[update: New DENG Build: 1.0.44]

I just published a new DENG build, that fixes some bugs and adds some minor features:

  • fixed: Memory leaks. Some object cross references prevented the DENG component from unloading.
  • fixed: Whitespace as first character in a block element with “white-space: normal” applied. Leading whitespace is now removed.
  • fixed: _level0 references and callbacks in deng.swf made it difficult to load DENG into custom Flash projects.
  • added: Support for <ul />. Unordered lists now display a bullet as marker.
  • added: Support for <br />. The line break tag now defaults to “display: block”.

As we are slowly moving to a different hosting, the sources are currently not available from CVS.

DENG 1.0.43 sources: http://deng.com.br/deng_1_0_43_src.rar

I also published a demo showing how to use DENG with Flash projects compiled with Flash MX 2004, Flash 8 or MTASC, and how to use a standard vertical scrollbar (here: UIScrollBar v2 component) with DENG.

Demo: http://deng.com.br/mx2004/
Download: http://deng.com.br/mx2004/deng.zip

By the way, the DENG support forum moved:
http://deng.com.br/forum/

Enjoy.