• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 434
  • Last Modified:

AS3 Display Object instantiation problem

I want to create two children that will be placed into a display object and then added to the display list. I know my code is close, but I get the following error:

1061: Call to a possibly undefined method addChild through a reference with static type flash.display:DisplayObject.

What am I doing wrong?
public function populateLogoAndFooter() {
  //Create a container for the children
  var lfContainer:DisplayObject = new DisplayObject();
  addChild(lfContainer);
  //----- Add Header logo
  var amLegacyLogo:Sprite=new americanLegacyLogo;
  amLegacyLogo.x=200;
  amLegacyLogo.y=18.8;
  lfContainer.addChild(amLegacyLogo);
  //----- Add footer type
  var baselineType:Sprite=new footerType;
  baselineType.x=166.3;
  baselineType.y=573.4;
  lfContainer.addChild(baselineType);
  //
  lfContainer.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
}

Open in new window

0
msukow
Asked:
msukow
  • 2
1 Solution
 
msukowAuthor Commented:
I figured that out - had to change the
var lfContainer:DisplayObject = new DisplayObject();
to
var lfContainer:Sprite= new Sprite();
0
 
msukowAuthor Commented:
However, Now I have a new issue. I have a listener attached to a button as follows:

public function populateNavigation() {
  //----- Film Info button
  var button1:filmInfo=new filmInfo;
  button1.x=84.1;
  button1.y=69.1;
  button1.buttonMode=true;
  button1.name="filmInfoButton";
  addChild(button1);
  button1.addEventListener(MouseEvent.MOUSE_UP, populateFilmInfo);
  button1.addEventListener(MouseEvent.MOUSE_OVER, navOver);
  button1.addEventListener(MouseEvent.MOUSE_OUT, navOut);
}

The populateFilmInfo function is as follows:
public function populateFilmInfo() {
  trace("populateFilmInfo reached");
  trace("lfContainer.x: " +lfContainer.x);
}

I get the following message when I compile and press the button1:
ArgumentError: Error #1063: Argument count mismatch on Main/populateFilmInfo(). Expected 0, got 1.
0
 
Aneesh ChopraCommented:
populateFilmInfo method should except an MouseEvent..

here is the updated code:

public function populateFilmInfo(evt:MouseEvent) {
  trace("populateFilmInfo reached");
  trace("lfContainer.x: " +lfContainer.x);
}

0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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