[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 853
  • Last Modified:

Is Flex SDK necessary for google maps

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
SimonAdrian
Asked:
SimonAdrian
  • 9
  • 8
1 Solution
 
asaivanCommented:
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
 
SimonAdrianAuthor Commented:
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
 
asaivanCommented:
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
asaivanCommented:
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
 
SimonAdrianAuthor Commented:
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
 
asaivanCommented:
Can you post all of your code? I will edit it, and repost.
0
 
SimonAdrianAuthor Commented:
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
 
asaivanCommented:
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
 
SimonAdrianAuthor Commented:
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
 
asaivanCommented:
No just leave it in the same folder as the FLA file.
0
 
asaivanCommented:
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
 
SimonAdrianAuthor Commented:
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
 
asaivanCommented:
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
 
SimonAdrianAuthor Commented:
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
 
SimonAdrianAuthor Commented:
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
 
asaivanCommented:
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
 
SimonAdrianAuthor Commented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now