AS3: Scale Flash Component with Browser Zoom

Apr 10, 2011 | ActionScript, Blog, Flash, Web

In a recent small project involving a homepage Flash slideshow, I needed to make the slideshow scale with browser zooming. Insert the code below into the main ActionScript file. Tested on Chrome, Firefox, Safari, and IE 7/8.

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE

stage.addEventListener(Event.RESIZE, onStageResize)
private function onStageResize(e:Event):void {
var widthScale:Number = stage.stageWidth / (original width of swf);
scaleX = scaleY = widthScale;
}

Google Maps API for 2 Domains (in Flash, AS3)

Google Maps can be easily integrated into Flash with an API key for the application’s domain. Though, since each Google Maps API key can only be assigned to one domain, if your website contains two domains reading the same server (example: www.mysite.com and www.mysite.org), you will need two separate API keys for each domain. While ideally I’d prefer to redirect one domain to the other, this isn’t always the case for how a client wants their site to read. In order for the SWF file containing Google Maps to load successfully in multiple domains, the ActionScript file needs to be edited accordingly. Though the final result can also be achieved using a combination of JavaScript and ExternalInterface in Flash, I found it easiest to use AS3′s LocalConnection to convert the SWF’s domain into a String and then indexed with an if/else statement to decide with API key ActionScript should use:

import flash.net.LocalConnection;
var lc:LocalConnection = new LocalConnection();
var domain:String = lc.domain;

if (domain.indexOf("com") != -1) {
	map.key = "key-A";
} else {
	map.key = "key-B";
}

map.setSize(new Point(P1, P2));
map.addEventListener(MapEvent.MAP_READY, onMapReady);
swfMovieClip.addChild(map);

More information on Google Maps API.

AS3, XML, CDATA – <strong> instead of <b>

Aug 15, 2010 | ActionScript, Blog, Flash, XML

With a recent Flash project, I was struggling to find a solution to display bolded HTML text from XML files that uses the <strong> tag. The reason I wanted to use <strong> instead of <b> was because the XMLs were being generated from MODx content management system. Since Flash cannot read the <strong> tag, I used the RegExp class in AS3 to find and replace <b> with <strong> in the XML content text before sending it to my htmlText in Flash to read. Below is the snippet of code is used:

var myPattern:RegExp = /strong/g;
var str:String = xml.content.toString();
contentTxt.htmlText = str.replace(myPattern, "b");

Though a simple solution, took me awhile a bit of research to arrive at the above conclusion. Therefore hope this saves some time for others!

Google Mashups and Flash (AS3)

I recently learned about Google Mashups from my boyfriend who relayed class material from his MS in Management of IT program, and luckily with perfect timing in relation to current projects. Essentially, Google Mashups can be defined as a web page or application that combines data or functionality from two or more external sources, resulting in a new service. For example, a Mashup can be created by integrating Google Maps into a personal web page, combining web page information with map data.

Two weeks ago I launched the website for Monticello Wine Trail, in which I utilized Google Mashups. One of the most important aspects of the MWT website is the ability for visitors to view and learn about the smaller trail clusters of wineries, grouped by their proximity to one another. In the previous website, the trail information was provided on a static JPG image. By integrating Google Maps into the Flash site, website visitors are able to interact (zoom and pan) with the maps, providing an overall more interactive user experience and more detailed map information.

google-mashups-api

Integrating Google Maps into Flash (via ActionScript 3.0) is quite easy and only requires the use of Google Maps API (which allows embedding of a Google Map into one’s web page using JavaScript). The following link walks through the steps for embedding Google Maps in Flash applications. Google also provides tutorials and a great selection of Flash and Flex demos from which to pull code.

Below are some links to additional resources:
Sign Up for the Google Maps API
Displaying Google Maps in Flash by Kirupa
Implement a Map Using the Google Map API for Flash by Activetuts+
Google Maps: 100+ Best Tools and Mashups by Mashable

Arnaud Icard & AS3

Jul 8, 2010 | ActionScript, Blog, Flash, Resource

icard-01

Secretly hoping my work slows down soon so I can test out Arnaud Icard‘s ActionScript 3.0 experiments posted on his blog. Code libraries include a cloth simulation built with Traer.physics port to AS3 (second image, link), a simple gesture recognition engine (top image, link), and 3D grass experiment with stitching sprite instances together seamlessly (third image, link). Wow.

Continue reading “Arnaud Icard & AS3” »