How do I get around the super-statement

Im trying to implement the content of a package with xml, which means that Im trying to use the package-code in the actual .fla-file.
But I have a problem with the super-statement, that creates this error:
1007: A super statement can be used only inside class instance constructors.

    import flash.events.Event;
    import com.google.maps.Map;
    import com.google.maps.MapEvent;
    import com.google.maps.MapType;
    import com.google.maps.LatLng;
      function initiateMap() {
      super();
      key = "Here there is a google maps key";
                addEventListener(MapEvent.MAP_READY, onMapReady);
              }
                  
              function onMapReady(event:MapEvent):void {
        setCenter(new LatLng(zlatitude,zlongitude), 7, MapType.HYBRID_MAP_TYPE);
}
}

In the code snippet you can see the package that Im trying to bring to use in the .fla-file.

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();
			  key = "Here there is a google maps key";
              addEventListener(MapEvent.MAP_READY, onMapReady);
              }
			 
              private function onMapReady(event:MapEvent):void {
				  
                  setCenter(new LatLng(zlatitude,zlongitude), 7, MapType.HYBRID_MAP_TYPE);
 
}
}
}

Open in new window

SimonAdrianAsked:
Who is Participating?
 
SimonAdrianConnect With a Mentor Author Commented:
I forgot to tell you that the google-code is in a component, that is in the library. Just leave it there.
0
 
SamuelRostolCommented:
In AS3.0, the call to super is added to the constructor by default, so you don't need to - so without giving you any clear answer to why you are getting an error-message, I can tell you that you will not loose anything by removing it in this case..

Kindly,
Samuel
0
 
SimonAdrianAuthor Commented:
Well, except I then get two - new - errors.
1120: Access of undefined property key.
1180: Call to a possibly undefined method setCenter.

Im not sure if they just didnt show up before, because of the existing super-statement or why....
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
SamuelRostolCommented:
Hi again.

Well, that's because you are trying to modify a variable that has not been defined yet, and you are trying to call a function that has not been created yet.

The following code should be compiled:
[CODESNIP]

Kindly,
Samuel
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 {
          var key :String;
          public function HelloWorld() {
			  super();
			  key = "Here there is a google maps key";
              addEventListener(MapEvent.MAP_READY, onMapReady);
              }
			 
              private function onMapReady(event:MapEvent):void {
                  setCenter(new LatLng(zlatitude,zlongitude), 7, MapType.HYBRID_MAP_TYPE);
 
	     }
	     private function setCenter(_lat :LatLng, _number :Number, _maptype) :void {
	     // CODE HERE
	     }
	}
}

Open in new window

0
 
SimonAdrianAuthor Commented:
Im not sure I follow the last part:
I got rid of the key-error, but Im not sure what to do with your suggestion of a setcenter-function. The function already exist in one of the imported classes - I assume, since the package-solution works fine.
Just to clarify: What Im trying to do is NOT using a package-solution - thats whats its all about, because Im trying to make it work based on xml-parameters.
I was hoping for something like what you see in the below codesnippet.
Thats based on my first codesnippet.


var xmlLoader:URLLoader = new URLLoader(); 
var xmlData:XML = new XML(); 
xmlLoader.addEventListener(Event.COMPLETE, LoadXML); 
xmlLoader.load(new URLRequest("map.xml")); 
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data); 
var zlatitude=xmlData.attribute("latitude");
var zlongitude=xmlData.attribute("longitude");
var zzoom=xmlData.attribute("zoom");
			import flash.events.Event;
    import com.google.maps.Map;
    import com.google.maps.MapEvent;
    import com.google.maps.MapType;
    import com.google.maps.LatLng;  
			  function HelloWorld() {
			  var key :String;
			  key = "Here theres a google map key";
              addEventListener(MapEvent.MAP_READY, onMapReady);
			  }
			  function onMapReady(event:MapEvent):void {
				  
                  setCenter(new LatLng(12,55), 7, MapType.HYBRID_MAP_TYPE);
 
} 
	     }

Open in new window

0
 
SamuelRostolCommented:
Ok, then you have to refer to the class where the setCenter-function is placed...

like:
var thatClass = new TheUsedClass();

then, later:
thatClass.setCenter(....)

Can you try that out?
0
 
SimonAdrianAuthor Commented:
Can you specify that for me.
Im pretty sure the function is in    com.google.maps.LatLng;
0
 
SimonAdrianAuthor Commented:
If I try it this way I get an error:

function onMapReady(event:MapEvent):void {
1136        var newlatlong = new com.google.maps.LatLng();
                  newlatlong.setCenter(new LatLng(12,55), 7, MapType.HYBRID_MAP_TYPE);

}

1136: Incorrect number of arguments.  Expected 2.
0
 
SamuelRostolCommented:
Hmm, I don't think the function is in LatLng, as the LatLng function is used within the setCenter-function...
0
 
SimonAdrianAuthor Commented:
Well, Ive tried with the others too,
When I use Map, I dont get errors, but apart from that nothing happens.
The other two gives me similar errors - respectively 2 and 3 expected numbers of arguments.
0
 
SamuelRostolCommented:
Can you possibly zip the project down and upload it somewhere, and I'll take a look?

Easier that way..
0
 
SimonAdrianAuthor Commented:
Sure.
http://www.dego.dk/zipped/helloworld.zip
It contains
helloworld.xml
helloworld.fla with my attempt to get around the use of
HelloWorld.as, which contains the working package-code.

If you refer to the HelloWorld.as in the Document class, you will see the map, whn you test the .fla.
Its presently Hybrid - if you want to change it to map-view, write NORMAL instead.
Bear over with me that I dont supply a google-maps key.
You can get one here if you have a google-account
http://code.google.com/apis/maps/signup.html
If necesseray I can upload a file for a short period with a key
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.