Archive for the ‘Tutorials’ Category

How to get GPS coordinates from Google Maps

In previous tutorial we made a simple google map in Flash. But how do we get desired coordinates of our location? You probably would like to show location of your company and set it as default map location. Getting coordinates is actually pretty simple.

Go to Google Maps and find the desired location. Now use right click and then select “center map here”. Now paste following code into browser URL:

javascript:void(prompt('',gApplication.getMap().getCenter()));

A pop up window with coordinates will appear. Just copy this coordinates and paste them to flash code:

map.setCenter(new LatLng(37.77114, -122.40159), 18, MapType.SATELLITE_MAP_TYPE);
var m:Marker = new Marker(new LatLng(37.77114, -122.40159),

coordinates for marker define exactly where marker of your location is placed.
And we’re done. Good luck using it in your projects.

Reading Google Maps API to Flash AS3

The use of google maps in flash AS3 is simple and straightforward.
First go to Google Maps API for Flash and download the zip file. Now extract the files and copy flash component file under lib directory to where you have flash installed (under component dir). Usually path is: C:\Program Files\Adobe\Adobe Flash CS4\language\Configuration\Components.
Now open Flash and go to components (window/components). You will see GoogleMapsLibrary under Google Maps API. Drag it to your library on stage.

Next you have to import neccessary classes:

import com.google.maps.*;
import com.google.maps.overlays.*;
import com.google.maps.controls.*;

Next step is definition of variables needed for map creation:

var map:Map = new Map();
map.key =
"ABQIAAAAqHHCopGV2FznT8V5ph6ELxShFIAhFb89IoGWiehHpBPf2E8vHxQ2wvPhcSdLLuc
6JxXYONuPAmqLRA";
map.setSize(new Point(stage.stageWidth, stage.stageHeight));
map.x = 0;
map.y = 0;
map.addEventListener(MapEvent.MAP_READY, onMapReady);

map.key defines the starting location of the map and can be found on google pages.
map.setSize defines the size of the map (in our case it is the size of the stage).
map.x and map.y define the position of map on stage.
Finally we add an event listener that will start a function to draw a map when map is ready.
In the end we add following code:

function onMapReady(e:Event):void
{
map.addControl(new ZoomControl());
map.addControl(new MapTypeControl());
map.setCenter(new LatLng(37.77114, -122.40159), 18, MapType.SATELLITE_MAP_TYPE);
var m:Marker = new Marker(new LatLng(37.77114, -122.40159),
new MarkerOptions({icon:new marker()}));
map.addOverlay(m);

}

All we have to do now is add map to the stage:

this.addChild(map);

Save and export movie and map with marker on Adobe location should appear.

CSS trick – how to trick browser to print backgrounds

Most of you that work with CSS and HTML are aware that you have no control over printing backgrounds and images, that is totally up to user to decide and there is no way to force printing. There is however a trick you can use to display what appears to be a background but it really isn’t.
Read more

Loading several external SWF files

In this tutorial I will show you how to load several external swf files and then move between them with forward and backward button. First we have to import UILoader. Add following code at the beginning:


import fl.containers.UILoader;

Next we will define an array of external swf files. Add following code:


var externalSWF:Array = ["test.swf",
"test1.swf",
"test2.swf",
"test3.swf"
];

Please note that in my case external swf files are in the same directory as the fla file we are creating. If your files are in subdirectories you have to provide a full path (“dir/test.swf”). Next we will define a variable that will tell which swf is current one.


var i:int = 0;

Value is set to 0 as that is our first swf file. Now we will define UIloader, sprite that will hold our swf’s and a movieclip that will hold current swf file that is on the stage.


var thisUILoader:UILoader = new UILoader();
thisUILoader.addEventListener(Event.INIT, loadFinish);
var theLoaderContext:LoaderContext;

var slideshow:Sprite = new Sprite();
var MC:MovieClip = new MovieClip();

After load is finished we will call function loadFinish. But first we have to put our sprite and movieclip to the stage.


addChild(slideshow);
slideshow.addChild(thisMC);

Now we can add function loadFinish.


function loadFinish(e:Event):void {
MC = MovieClip(thisUILoader.content);
thisUILoader.unload();
slideshow.addChild(thisMC);
setChildIndex(slideshow, 0);
backward.addEventListener(MouseEvent.CLICK, backwardF);
forward.addEventListener(MouseEvent.CLICK, forwardF);
}

First we load content of swf file then we add it to slideshow and set index to 0. Now create two simple movieclips named backward and forward. Don’t forget to set instance names of these movieclips to backward and forward. We will use these buttons to move between swf files.

Now we need to add functions for moving forward and backward and we have to add another variable that will count swf files. Add following code to the start of the file where variables are.


var counter:int = 0;

Now add functions for forward and backward.


function backwardF(e:MouseEvent){
i--;
if (i < 0)
i = 5;
nextSWF();
counter++;
}
function forwardF(e:MouseEvent){
if (i == 5)
i = -1;
i++;
nextSWF();
counter++;
}

Now we only have to add function nextSWF.


function nextClip():void {
theLoaderContext = new LoaderContext();
theLoaderContext.applicationDomain = new ApplicationDomain();
thisUILoader.load( new URLRequest(clips[i]),theLoaderContext);
}

This function loads the current swf file. Starting value of i is 0 (first swf in array).
Now add following code at the end to start loading.


nextClip();

And we are finished. You can now load as many swf files as you wish and move between them.
Thank you for reading

Flash blurry movement

Ever wanted to move your movie clip in a way that it would look like it is moving really fast? In this tutorial I will show you how to add a simple blur filter to enhance movement effect. First add some movie clip to the stage. I simply made a circle, converted it to movie clip and named it circle.
Read more

Return top

Flash applications and animations is Digg proof thanks to caching by WP Super Cache