?
Solved

How do I get around the super-statement

Posted on 2008-06-24
12
Medium Priority
?
1,179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 

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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to how to record live broadcast.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

777 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