Solved

Is Flex SDK necessary for google maps

Posted on 2008-06-18
17
829 Views
Last Modified: 2012-06-22
Im trying to use the Google Maps API for flash, but is unsure if its really necessary to use flex to compile the SWF-file or its just a way for people that havent got Flash CS3, to compile an as-file into one.
http://code.google.com/apis/maps/documentation/flash/basics.html
When I try to follow their instruction - apart from the compiling in Flex SDK -part -  I get this error, which I dont understand:
"1037: Packages cannot be nested."
Im not to familiar with AS3, but I hope I can stay within Flash.

0
Comment
Question by:SimonAdrian
  • 9
  • 8
17 Comments
 
LVL 9

Expert Comment

by:asaivan
ID: 21812287
Simple answer as I can give.  No you don't.  You can use both  the Flash IDE or Flex.  The packages cannot be nested error comes from how you built your code.  You probably have two package statements in there somewhere, one inside another. :)
0
 

Author Comment

by:SimonAdrian
ID: 21814513
Ok, Just wanted to be sure.

This is the google-code - meant for an .as-file - I try to use in the Flash IDE:

package com.google.maps.examples {
    import flash.events.Event;
    import com.google.maps.Map;
    import com.google.maps.MapEvent;
    import com.google.maps.MapType;
    import com.google.maps.LatLng;
      public class HelloWorld extends Map {
          public function HelloWorld() {
              super();
              addEventListener(MapEvent.MAP_READY, onMapReady);
              }
              private function onMapReady(event:MapEvent):void {
                  setCenter(new LatLng(40.736072,-73.992062), 14, MapType.NORMAL_MAP_TYPE);
}
}
}

I recon the problem is that the code is meant to be in an as.file, thats meant to be compiled in Flex.
0
 
LVL 9

Expert Comment

by:asaivan
ID: 21814673
I see.   The package definition isn't right.  It can be used in Flash no problem, but the issue is that the code should just be

package
{
    import flash.events.Event;
    import com.google.maps.Map;
    import com.google.maps.MapEvent;
    import com.google.maps.MapType;
    import com.google.maps.LatLng;
      public class HelloWorld extends Map {.... etc.

The package definition com.google.maps.examples is due to the fact that the as file itself resides in a folder structure of com->google->maps->examples.  When you're using an AS file which is right in the same directory as the FLA file, you don't need to specify any package definition other than package.  Hope that helps. :)
0
 
LVL 9

Expert Comment

by:asaivan
ID: 21814723
Also, I should add, if you're not familiar with the new Flash Document Class, then I'll explain it if that's the case.

In a new AS3 file, what you would do is enter the name (no .as though) of the AS file you want to be the main file for Flash in the Document class text field in the Properties menu (usually at the bottom of the screen).  Like if your Google Maps thing is titled Map.as, then enter Map in the Document class field, then hit cntrl->enter to export the Flash SWF.  That's how you'd do it in the Flash IDE.  

0
 

Author Comment

by:SimonAdrian
ID: 21814771
Thanks, but when I remove the part after  package, I still get the same error:
1037: Packages cannot be nested.
Do you mean that package isnt neccessary at all.
When I try this:

    import flash.events.Event;
    import com.google.maps.Map;
    import com.google.maps.MapEvent;
    import com.google.maps.MapType;
    import com.google.maps.LatLng;
      public class HelloWorld extends Map {

I get this error:
1114: The public attribute can only be used inside a package.

I know I ought to learn AS3 from start, but I really would like to get this to work without having to right now.
0
 
LVL 9

Expert Comment

by:asaivan
ID: 21814830
Can you post all of your code? I will edit it, and repost.
0
 

Author Comment

by:SimonAdrian
ID: 21815030
Well.
This is all of the code

package com.google.maps.examples {
    import flash.events.Event;
    import com.google.maps.Map;
    import com.google.maps.MapEvent;
    import com.google.maps.MapType;
    import com.google.maps.LatLng;
      public class HelloWorld extends Map {
          public function HelloWorld() {
              super();
              addEventListener(MapEvent.MAP_READY, onMapReady);
              }
              private function onMapReady(event:MapEvent):void {
                  setCenter(new LatLng(40.736072,-73.992062), 14, MapType.NORMAL_MAP_TYPE);
}
}
}
0
 
LVL 9

Expert Comment

by:asaivan
ID: 21815140
I think the main problem here is that you have to use a Document class.  You can't put the code directly in the actions panel in this case.  Because its a package is already declared, although you can't see it, in the actions panel.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:SimonAdrian
ID: 21815432
Ok, Now Ive placed all the code in HelloWorld.as, and has written HelloWorld in the Properties-field Document class.
Ive placed the .as-file in the same folder as the .fla-file and the com-folder, although Im not quite sure what to make of this part of the google tutorial:
-----------------------
ActionScript packages contain groups of related code and implicitly define a namespace that uniquely identifies that code. The package name acts as a prefix to any classes contained in the package (so the HelloWorld class above within package com.google.maps.examples defines the com.google.maps.examples.HelloWorld class).
------------------------
Its nonsense to me, but from that it looks as if I should place the .as-file in examples-folder. Or what.





0
 
LVL 9

Expert Comment

by:asaivan
ID: 21815499
No just leave it in the same folder as the FLA file.
0
 
LVL 9

Expert Comment

by:asaivan
ID: 21815577
My apologies, I've been reading up on this and apparently you CAN'T use the Flash API in the Flash IDE!!  However, after doing some searching on the Google Code repo, some whiz kid has wrapped the Flex SWC to be able to work in the Flash IDE.  Here's the link.

http://gmaps-api-issues.googlecode.com/issues/attachment?aid=1870792347331227355&name=map_flash_1_4.swc

"I have hacked together an SWC component file that can be imported and used in the
Flash CS3 authoring environment that wraps the Google Maps swc.

You add the component normally (...Local Settings\Application Data\Adobe\Flash CS3
\en\Configuration\Components\).

Then you can add it to your library (don't drag it on to the stage) and use the
classes in the API through Flash."

Let me know how this works for you.
0
 

Author Comment

by:SimonAdrian
ID: 21823010
Thanks, it works - partly.
It only works if I put the GoogleMaps key in as a flashvars.
I think its simply because I dont understand what they mean by the "ActionScript development directory":

"This helloworld.mxml file should be placed in the root of the ActionScript development directory; doing so implicitly defines the location for your ActionScript code within your com/google/maps/examples development directory."

See defintion of helloworld.mxml in codesnippet

In order to display your Flash map on a webpage, you will at least need a minimal MXML declaration. This declaration will specify the UI container, the class to instantiate, and the namespace for your application code. A sample MXML declaration named helloworld.mxml appears below:
 

<?xml version="1.0" encoding="utf-8"?>

<examples:HelloWorld xmlns:examples="com.google.maps.examples.*" key="ABCDEF" width="800" height="600"/>
 

This MXML declaration specifies only one UI component: an object of class "HelloWorld" attached to the examples namespace, which is defined as "com.google.maps.examples.*" The MXML declaration also specifies width and height parameters. More importantly, the MXML declaration acts as a convenient location to place your unique API key.
 

This helloworld.mxml file should be placed in the root of the ActionScript development directory; doing so implicitly defines the location for your ActionScript code within your com/google/maps/examples development directory.

Open in new window

0
 
LVL 9

Expert Comment

by:asaivan
ID: 21823111
What's your code look like in AS where you're trying to enter the key?  I was having some trouble yesterday with keys and Firefox where I had to do the same thing, put two different keys in as flashvars depending on the URL, so I'm curious.
0
 

Author Comment

by:SimonAdrian
ID: 21823275
The key should get into .swf from the .mxml-file if only I could figure out where to place it.

Can you tell me what the "root of the ActionScript development directory" means. Is it the place where the helloWorld.as and .fla is placed or does it mean in the classes-directory.
 
The .as is just the same code as yesterday:

package
{
    import flash.events.Event;
    import com.google.maps.Map;
    import com.google.maps.MapEvent;
    import com.google.maps.MapType;
    import com.google.maps.LatLng;
      public class HelloWorld extends Map {
          public function HelloWorld() {
              super();
              addEventListener(MapEvent.MAP_READY, onMapReady);
              }
              private function onMapReady(event:MapEvent):void {
                  setCenter(new LatLng(40.736072,-73.992062), 14, MapType.NORMAL_MAP_TYPE);
}
}
}
0
 

Author Comment

by:SimonAdrian
ID: 21823566
Sorry I think I misunderstood you.
Earlier today Ive tried to follow a tutorial that incorporates google Maps in Flex Builder 3.0
http://scriptplayground.com/tutorials/as/Installing-and-Using-Google-Maps-in-Flex

I havent been able to make it work, but if you take a look at the private function here:

private function init():void
      {
            gMap = new Map();
            gMap.key = "{YOUR_API_KEY_HERE}";
            gMap.width = 600;
            gMap.height = 400;
            gMap.addEventListener(MapEvent.MAP_READY, mapReadyHandler);

            mapContainer.addChild(gMap);
      }

then maybe you can figure out how to include the API-key in the .as




<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 

  width="100%" height="100%" initialize="init()">

		

	<mx:Script>

	<![CDATA[
 

	import com.google.maps.Map;

	import com.google.maps.MapEvent;

	import com.google.maps.MapType;

	import com.google.maps.LatLng;

		

	private var gMap:Map;
 

	private function init():void

	{

		gMap = new Map();

		gMap.key = "{YOUR_API_KEY_HERE}";

		gMap.width = 600;

		gMap.height = 400;

		gMap.addEventListener(MapEvent.MAP_READY, mapReadyHandler);
 

		mapContainer.addChild(gMap);

	}

	

	private function mapReadyHandler(e:MapEvent):void

	{

		gMap.setCenter(new LatLng(42.334184,-71.018372), 13, MapType.HYBRID_MAP_TYPE);

		gMap.setSize(new Point(mapContainer.width, mapContainer.height)); 

	}

		

	]]>

	</mx:Script>

		

	<mx:UIComponent id="mapContainer" width="100%" height="100%"/>

	

</mx:Application>

Open in new window

0
 
LVL 9

Accepted Solution

by:
asaivan earned 500 total points
ID: 21823607
Ok.  "Root of the ActionScript development directory" means the main folder structure's root folder.  That is, if you have a folder structure of:

src
|-------------------------------------
|                   |                         |
images         view                   control
                                               |
                                               components

or something like that, that "src" would be your root folder where your main MXML file is.  

However, you don't need to worry about that, cause you're not using Flex or MXML.  

Basically, MXML compiles down to AS, so everything you can write in MXML you can also write in AS.  So, following this principal, if you look at the MXML code given in the Google Maps tutorial, you'll see in the MXML Map node a property named "key" with the API Key in a long string after it.  What this means is that the Map class, contains a property named "key", which takes as an argument a String which is the API key.

Anyhow, to bring that down to simplest terms, all you need to do is add to your AS code:

public function HelloWorld() {
              super();

              key = "insert-your-google-API-key-here";

              addEventListener(MapEvent.MAP_READY, onMapReady);
              }

I know that's a lot to digest.  Hope that helps though.
0
 

Author Closing Comment

by:SimonAdrian
ID: 31468874
Thanks. Finally I got it to work.  You certainly deserved your point a long time ago, but Im gratefull for your patience.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now