Solved

How do I get around the super-statement

Posted on 2008-06-24
12
1,169 Views
Last Modified: 2013-11-11
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

0
Comment
Question by:SimonAdrian
  • 7
  • 5
12 Comments
 
LVL 12

Expert Comment

by:SamuelRostol
ID: 21854344
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
 

Author Comment

by:SimonAdrian
ID: 21855518
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
 
LVL 12

Expert Comment

by:SamuelRostol
ID: 21864214
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
 

Author Comment

by:SimonAdrian
ID: 21864910
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
 
LVL 12

Expert Comment

by:SamuelRostol
ID: 21864945
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
 

Author Comment

by:SimonAdrian
ID: 21865271
Can you specify that for me.
Im pretty sure the function is in    com.google.maps.LatLng;
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:SimonAdrian
ID: 21865351
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
 
LVL 12

Expert Comment

by:SamuelRostol
ID: 21872689
Hmm, I don't think the function is in LatLng, as the LatLng function is used within the setCenter-function...
0
 

Author Comment

by:SimonAdrian
ID: 21873455
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
 
LVL 12

Expert Comment

by:SamuelRostol
ID: 21873828
Can you possibly zip the project down and upload it somewhere, and I'll take a look?

Easier that way..
0
 

Author Comment

by:SimonAdrian
ID: 21874128
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
 

Accepted Solution

by:
SimonAdrian earned 0 total points
ID: 21874145
I forgot to tell you that the google-code is in a component, that is in the library. Just leave it there.
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

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
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.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

744 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

11 Experts available now in Live!

Get 1:1 Help Now