Skip to main content
Inspiring
June 8, 2011
Answered

Constructor not being accessed by linked movieclip

  • June 8, 2011
  • 1 reply
  • 1190 views

I have several movieclips on the stage. They are linked (via properties - as linkage) to a class I created (GeoPuzzle).

The constructor calls several methods and has several properties that I set in the main timeline.

These methods are never accessed. I'm missing something obvious, but I don't know how to make these methods run, since they are in the contructor.

Here is my code (simplified):

public class GeoPuzzle extends MovieClip {
        public var abbrev:String;
        public var fullName:String;
        public var isLocked:Boolean;
       
        public function GeoPuzzle (abbrev:String, fullName:String, isLocked:Boolean):void {
            this.abbrev = abbrev;
            this.fullName = fullName;
            this.isLocked = isLocked;
            if (this.isLocked == true) {
                this.gotoAndStop ("Lock");
            }
            this.addEventListener(TouchEvent.TOUCH_BEGIN, geoTouchBeginHandler);
        }
    }

The event listener is never added to the movie clips. Why? What should I be doing in the main timeline? After linking the movie clip and naming the instance, I'm not sure what to do after that to call the constructor method.

Thanks!
Amber

This topic has been closed for replies.
Correct answer kglad

Now, I didn't create class definitions for every single state. I just created GeoPuzzle. And then put in each state's actionscript linkage GeoPuzzle.StateName. When I hit "validate class name" it says "A definition for this class could not be found in the classpath, so one will be automatically generated in the SWF file upon export."

I assumed that meant that I could just treat all the objects as if they were instances of the GeoPuzzle class without having to create different classes for all 50 states. That the constructor for, say, GeoPuzzle.Arizona would just automatically be empty and it would inherit everything from GeoPuzzle. Did I assume wrong?


you assumed wrong.

flash doesn't know GeoPuzzle.Arizona should inherit from GeoPuzzle.  flash thinks there should be an Arizona class in a GeoPuzzle directory.

to remedy, you must change the base class of your GeoPuzzle.StateName library objects to:

com.freerangeeggheads.puzzleography.GeoPuzzle

currently they probably all have a base class of

flash.display.MovieClip

1 reply

kglad
Community Expert
Community Expert
June 8, 2011

where's geoTouchBeginHandler()?

and in your main timeline, if that's where you're instantiating class members, you should be using:

var gp:GeoPuzzle=new GeoPuzzle(string1,string2,boolean);

addChild(gp);

gp.x=

gp.y=

etc

AmbariAuthor
Inspiring
June 8, 2011

Okay, so I should remove everything from the stage, write down their current X and Y coordinates, and then dynamically instantiate all the puzzle pieces to the stage using a "var" call?

(And geoTouchBeginHandler is in the main timeline, because it contains a line of code that won't function in the class: displayName.gotoAndStop() gives me an error because displayName is instantiated in the mainTimeline and the compiler can't access it from the class definition (would be my guess).

kglad
Community Expert
Community Expert
June 8, 2011
Okay, so I should remove everything from the stage, write down their current X and Y coordinates, and then dynamically instantiate all the puzzle pieces to the stage using a "var" call?
you must do that IF you have parameters required by the constructor

(And geoTouchBeginHandler is in the main timeline, because it contains a line of code that won't function in the class: displayName.gotoAndStop() gives me an error because displayName is instantiated in the mainTimeline and the compiler can't access it from the class definition (would be my guess).

i don't know what displayName is so i can't comment about where that should be located but if the listener function is on the main timeline, then the listener must be in the main timeline