Skip to main content
Known Participant
February 11, 2014
Question

1046: Type was not found or was not a compile-time constant.

  • February 11, 2014
  • 1 reply
  • 10127 views

Hi i am having some trouble with some of my school coursework, i am trying to create a drag and drop system where i add a copy of an item of clothing onto the stage that can be dragged onto a mannequin but i cannot get the clothes to work i think that there is an issue with the variables but i cannot work out what it is.

1046: Type was not found or was not a compile-time constant: strappyTop.

1046: Type was not found or was not a compile-time constant: blackLongTop.

1046: Type was not found or was not a compile-time constant: pinkTop.

1046: Type was not found or was not a compile-time constant: noStraps.

1046: Type was not found or was not a compile-time constant: blacktop.

1046: Type was not found or was not a compile-time constant: sequinsTop.

1046: Type was not found or was not a compile-time constant: redtop.

1046: Type was not found or was not a compile-time constant: vesttop.

1046: Type was not found or was not a compile-time constant: pinkShirt.

1046: Type was not found or was not a compile-time constant: greyTop.

thank you

package

{

import flash.display.MovieClip;

import flash.events.Event;

import flash.events.MouseEvent;

import flash.display.DisplayObject;

public class Main extends MovieClip

{

  //Declare Variables

  var _isDragging:Boolean;

  var homePage:HomePage;

  var instructionsPage:InstructionsPage;

  var selectGenderPage:SelectGenderPage;

  var femaleDragAndDropPage:FemaleDragAndDropPage;

  var maleDragAndDropTopsPage:MaleDragAndDropTopsPage;

  var maleDragAndDropBottomsPage:MaleDragAndDropBottomsPage;

  var maleDragAndDropShoesPage:MaleDragAndDropShoesPage;

  var femaleModelPage:FemaleModelPage;

  var maleModelPage:MaleModelPage;

  var mailingListPage:MailingListPage;

  var thankYouPage:ThankYouPage;

 

  var strappyTop:strappyTop;

  var blackLongTop:blackLongTop;

  var pinkTop:pinkTop;

  var noStraps:noStraps;

  var blacktop:blacktop;

  var sequinsTop:sequinsTop;

  var redtop:redtop;

  var vesttop:vesttop;

  var pinkShirt:pinkShirt;

  var greyTop:greyTop;

 

  public function Main()

  {

   _isDragging = false;

   homePage = new HomePage();

   instructionsPage = new InstructionsPage();

   selectGenderPage = new SelectGenderPage();

   femaleDragAndDropPage = new FemaleDragAndDropPage();

   maleDragAndDropTopsPage = new MaleDragAndDropTopsPage();

   maleDragAndDropBottomsPage = new MaleDragAndDropBottomsPage();

   maleDragAndDropShoesPage = new MaleDragAndDropShoesPage();

   femaleModelPage = new FemaleModelPage();

   maleModelPage = new MaleModelPage();

   mailingListPage = new MailingListPage();

   thankYouPage = new ThankYouPage();

   addChild(homePage);

  

   strappyTop = new strappyTop();

   blackLongTop = new blackLongTop();

   pinkTop = new pinkTop();

   noStraps = new noStraps();

   blacktop = new blacktop();

   sequinsTop = new sequinsTop();

   redtop = new redtop();

   vesttop = new vesttop();

   pinkShirt = new pinkShirt();

   greyTop = new greyTop();

  

   //Add event listeners

   homePage.nextButton.addEventListener(MouseEvent.CLICK, onNextButtonClick)

   instructionsPage.nextButton2.addEventListener(MouseEvent.CLICK, onNextButton2Click)

   selectGenderPage.femaleImage.addEventListener(MouseEvent.CLICK, onFemaleImageClick)

   selectGenderPage.maleImage.addEventListener(MouseEvent.CLICK, onMaleImageClick)

   femaleDragAndDropPage.femaleMenu.nextButton3.addEventListener(MouseEvent.CLICK, onNextButton3Click)

   maleDragAndDropTopsPage.nextButton6.addEventListener(MouseEvent.CLICK, onNextButton6Click)

   maleDragAndDropBottomsPage.nextButton7.addEventListener(MouseEvent.CLICK, onNextButton7Click)

   maleDragAndDropShoesPage.nextButton8.addEventListener(MouseEvent.CLICK, onNextButton8Click)

   femaleModelPage.editFemale.addEventListener(MouseEvent.CLICK, onEditFemaleClick)

   maleModelPage.editMale.addEventListener(MouseEvent.CLICK, onEditMaleClick)

   femaleModelPage.signUpFemale.addEventListener(MouseEvent.CLICK, onSignUpFemaleClick)

   maleModelPage.signUpMale.addEventListener(MouseEvent.CLICK, onSignUpMaleClick)

   mailingListPage.nextButton9.addEventListener(MouseEvent.CLICK, onNextButton9Click)

   thankYouPage.finalHomeButton.addEventListener(MouseEvent.CLICK, onFinalHomeButtonClick)

   //Add event listeners drag and drop

   femaleDragAndDropPage.femaleMenu.top1.addEventListener(MouseEvent.CLICK,top1add);

   femaleDragAndDropPage.femaleMenu.top2.addEventListener(MouseEvent.CLICK,top2add);

   femaleDragAndDropPage.femaleMenu.top3.addEventListener(MouseEvent.CLICK,top3add);

   femaleDragAndDropPage.femaleMenu.top4.addEventListener(MouseEvent.CLICK,top4add);

   femaleDragAndDropPage.femaleMenu.top5.addEventListener(MouseEvent.CLICK,top5add);

   femaleDragAndDropPage.femaleMenu.top6.addEventListener(MouseEvent.CLICK,top6add);

   femaleDragAndDropPage.femaleMenu.top7.addEventListener(MouseEvent.CLICK,top7add);

   femaleDragAndDropPage.femaleMenu.top8.addEventListener(MouseEvent.CLICK,top8add);

   femaleDragAndDropPage.femaleMenu.top9.addEventListener(MouseEvent.CLICK,top9add);

   femaleDragAndDropPage.femaleMenu.top10.addEventListener(MouseEvent.CLICK,top10add);

  

   femaleDragAndDropPage.femaleMenu.stop();

  }

  //Event handlers

  function onNextButtonClick(event:MouseEvent):void

  {

   addChild(instructionsPage);

   removeChild(homePage);

  }

  function onNextButton2Click(event:MouseEvent):void

  {

   addChild(selectGenderPage);

   removeChild(instructionsPage);

  }

  function onFemaleImageClick(event:MouseEvent):void

  {

   addChild(femaleDragAndDropPage);

   removeChild(selectGenderPage);

  }

  function onMaleImageClick(event:MouseEvent):void

  {

   addChild(maleDragAndDropTopsPage);

   removeChild(selectGenderPage);

  }

  function onNextButton6Click(event:MouseEvent):void

  {

   addChild(maleDragAndDropBottomsPage);

   removeChild(maleDragAndDropTopsPage);

  }

  function onNextButton7Click(event:MouseEvent):void

  {

   addChild(maleDragAndDropShoesPage);

   removeChild(maleDragAndDropBottomsPage);

  }

  function onNextButton8Click(event:MouseEvent):void

  {

   addChild(maleModelPage);

   removeChild(maleDragAndDropShoesPage);

  }

  function onEditFemaleClick(event:MouseEvent):void

  {

   addChild(femaleDragAndDropPage);

   removeChild(femaleModelPage);

  }

  function onEditMaleClick(event:MouseEvent):void

  {

   addChild(maleDragAndDropTopsPage);

   removeChild(maleModelPage);

  }

  function onSignUpFemaleClick(event:MouseEvent):void

  {

   addChild(mailingListPage);

   removeChild(femaleModelPage);

  }

  function onSignUpMaleClick(event:MouseEvent):void

  {

   addChild(mailingListPage);

   removeChild(maleModelPage);

  }

  function onNextButton9Click(event:MouseEvent):void

  {

   addChild(thankYouPage);

   removeChild(mailingListPage);

  }

  function onFinalHomeButtonClick(event:MouseEvent):void

  {

   addChild(homePage);

   removeChild(thankYouPage);

  }

  function onNextButton3Click(event:MouseEvent):void

  {

   femaleDragAndDropPage.femaleMenu.gotoAndStop(3)

  }

  function onNext5ButtonClick(event:MouseEvent):void

  {

   femaleDragAndDropPage.femaleMenu.gotoAndStop(2)

  }

 

  function top1add(event:MouseEvent)

  {

   addChild(strappyTop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top2add(event:MouseEvent)

  {

   addChild(blackLongTop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top3add(event:MouseEvent)

  {

   addChild(pinkTop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top4add(event:MouseEvent)

  {

   addChild(noStraps)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top5add(event:MouseEvent)

  {

   addChild(blacktop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top6add(event:MouseEvent)

  {

   addChild(sequinsTop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top7add(event:MouseEvent)

  {

   addChild(redtop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top8add(event:MouseEvent)

  {

   addChild(vesttop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top9add(event:MouseEvent)

  {

   addChild(pinkShirt)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top10add(event:MouseEvent)

  {

   addChild(greyTop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

 

  private function testMouseUp(event:Event):void

  {

   var currentDragObject:MovieClip = event.currentTarget as MovieClip;

   currentDragObject.stopDrag();

   _isDragging = false;

   currentDragObject.removeEventListener(MouseEvent.MOUSE_UP, testMouseUp);

  

   //Find the name of the object over which the drag object is dropped

  }

  private function testMouseDown(event:Event):void

  {

   var currentDragObject:MovieClip = event.currentTarget as MovieClip;

   currentDragObject.startDrag();

   _isDragging = true;

   currentDragObject.addEventListener(MouseEvent.MOUSE_UP, testMouseUp);

  }

}

}

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
February 11, 2014

THere should be a difference between variable names and class names.

  var strappyTop:strappyTop;

  var blackLongTop:blackLongTop;

  var pinkTop:pinkTop;

  var noStraps:noStraps;

  var blacktop:blacktop;

  var sequinsTop:sequinsTop;

  var redtop:redtop;

  var vesttop:vesttop;

  var pinkShirt:pinkShirt;

  var greyTop:greyTop;

   strappyTop = new strappyTop();

   blackLongTop = new blackLongTop();

   pinkTop = new pinkTop();

   noStraps = new noStraps();

   blacktop = new blacktop();

   sequinsTop = new sequinsTop();

   redtop = new redtop();

   vesttop = new vesttop();

   pinkShirt = new pinkShirt();

   greyTop = new greyTop();

Basically, you cannot name a variable the same as a class.  It is standard to do what you did earlier which is to define the class names using a capital letter for the first letter...

  var strappyTop:StrappyTop;

  var blackLongTop:BlackLongTop;

  var pinkTop:PinkTop;

  var noStraps:NoStraps;

  var blacktop:blacktop;

  var sequinsTop:SequinsTop;

  etc...

and make sure you define the classes using the capitalized names

Known Participant
February 12, 2014

Thank you very much for your responce.

I changed the classes so they were capetalised and they now work perfectly; however, when i exported it as SWF movie, I could only view up to the 'tops' page and rather than being able to drag and drop the tops, you could only click them and they would appear in random places on the page. I therefore added the coding for both buttons so ypu could get from the tops page to the bottoms page and then to the shoes page. After doing this, I recieved '

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at Main()'. As well as this error, the pages just kept flashing so the tops, bottoms and shoes page kept automatically changing without me even being able to select any on the 'next' buttons to test if the work.

Any ideas how I can get my pages to only move to the next one when the 'next' button is selected, how to resolve the error or how to make the drag and drop section work?

Any help is much apprectiated.

My new code is:

package

{

import flash.display.MovieClip;

import flash.events.Event;

import flash.events.MouseEvent;

import flash.display.DisplayObject;

public class Main extends MovieClip

{

  //Declare Variables

  var _isDragging:Boolean;

  var homePage:HomePage;

  var instructionsPage:InstructionsPage;

  var selectGenderPage:SelectGenderPage;

  var femaleDragAndDropPage:FemaleDragAndDropPage;

  var maleDragAndDropTopsPage:MaleDragAndDropTopsPage;

  var maleDragAndDropBottomsPage:MaleDragAndDropBottomsPage;

  var maleDragAndDropShoesPage:MaleDragAndDropShoesPage;

  var femaleModelPage:FemaleModelPage;

  var maleModelPage:MaleModelPage;

  var mailingListPage:MailingListPage;

  var thankYouPage:ThankYouPage;

 

  var strappyTop:StrappyTop;

  var blackLongTop:BlackLongTop;

  var pinkTop:PinkTop;

  var noStraps:NoStraps;

  var blacktop:Blacktop;

  var sequinsTop:SequinsTop;

  var redtop:Redtop;

  var vesttop:Vesttop;

  var pinkShirt:PinkShirt;

  var greyTop:GreyTop;

 

  public function Main()

  {

   _isDragging = false;

   homePage = new HomePage();

   instructionsPage = new InstructionsPage();

   selectGenderPage = new SelectGenderPage();

   femaleDragAndDropPage = new FemaleDragAndDropPage();

   maleDragAndDropTopsPage = new MaleDragAndDropTopsPage();

   maleDragAndDropBottomsPage = new MaleDragAndDropBottomsPage();

   maleDragAndDropShoesPage = new MaleDragAndDropShoesPage();

   femaleModelPage = new FemaleModelPage();

   maleModelPage = new MaleModelPage();

   mailingListPage = new MailingListPage();

   thankYouPage = new ThankYouPage();

   addChild(homePage);

  

   strappyTop = new StrappyTop();

   blackLongTop = new BlackLongTop();

   pinkTop = new PinkTop();

   noStraps = new NoStraps();

   blacktop = new Blacktop();

   sequinsTop = new SequinsTop();

   redtop = new Redtop();

   vesttop = new Vesttop();

   pinkShirt = new PinkShirt();

   greyTop = new GreyTop();

  

   //Add event listeners

   homePage.nextButton.addEventListener(MouseEvent.CLICK, onNextButtonClick)

   instructionsPage.nextButton2.addEventListener(MouseEvent.CLICK, onNextButton2Click)

   selectGenderPage.femaleImage.addEventListener(MouseEvent.CLICK, onFemaleImageClick)

   selectGenderPage.maleImage.addEventListener(MouseEvent.CLICK, onMaleImageClick)

   femaleDragAndDropPage.femaleMenu.nextButton3.addEventListener(MouseEvent.CLICK, onNextButton3Click)

   femaleDragAndDropPage.femaleMenu.nextButton4.addEventListener(MouseEvent.CLICK, onNextButton4Click)

   femaleDragAndDropPage.femaleMenu.nextButton5.addEventListener(MouseEvent.CLICK, onNextButton5Click)

   maleDragAndDropTopsPage.nextButton6.addEventListener(MouseEvent.CLICK, onNextButton6Click)

   maleDragAndDropBottomsPage.nextButton7.addEventListener(MouseEvent.CLICK, onNextButton7Click)

   maleDragAndDropShoesPage.nextButton8.addEventListener(MouseEvent.CLICK, onNextButton8Click)

   femaleModelPage.editFemale.addEventListener(MouseEvent.CLICK, onEditFemaleClick)

   maleModelPage.editMale.addEventListener(MouseEvent.CLICK, onEditMaleClick)

   femaleModelPage.signUpFemale.addEventListener(MouseEvent.CLICK, onSignUpFemaleClick)

   maleModelPage.signUpMale.addEventListener(MouseEvent.CLICK, onSignUpMaleClick)

   mailingListPage.nextButton9.addEventListener(MouseEvent.CLICK, onNextButton9Click)

   thankYouPage.finalHomeButton.addEventListener(MouseEvent.CLICK, onFinalHomeButtonClick)

   //Add event listeners drag and drop

   femaleDragAndDropPage.femaleMenu.top1.addEventListener(MouseEvent.CLICK,top1add);

   femaleDragAndDropPage.femaleMenu.top2.addEventListener(MouseEvent.CLICK,top2add);

   femaleDragAndDropPage.femaleMenu.top3.addEventListener(MouseEvent.CLICK,top3add);

   femaleDragAndDropPage.femaleMenu.top4.addEventListener(MouseEvent.CLICK,top4add);

   femaleDragAndDropPage.femaleMenu.top5.addEventListener(MouseEvent.CLICK,top5add);

   femaleDragAndDropPage.femaleMenu.top6.addEventListener(MouseEvent.CLICK,top6add);

   femaleDragAndDropPage.femaleMenu.top7.addEventListener(MouseEvent.CLICK,top7add);

   femaleDragAndDropPage.femaleMenu.top8.addEventListener(MouseEvent.CLICK,top8add);

   femaleDragAndDropPage.femaleMenu.top9.addEventListener(MouseEvent.CLICK,top9add);

   femaleDragAndDropPage.femaleMenu.top10.addEventListener(MouseEvent.CLICK,top10add);

  

   femaleDragAndDropPage.femaleMenu.stop();

  }

  //Event handlers

  function onNextButtonClick(event:MouseEvent):void

  {

   addChild(instructionsPage);

   removeChild(homePage);

  }

  function onNextButton2Click(event:MouseEvent):void

  {

   addChild(selectGenderPage);

   removeChild(instructionsPage);

  }

  function onFemaleImageClick(event:MouseEvent):void

  {

   addChild(femaleDragAndDropPage);

   removeChild(selectGenderPage);

  }

  function onMaleImageClick(event:MouseEvent):void

  {

   addChild(maleDragAndDropTopsPage);

   removeChild(selectGenderPage);

  }

  function onNextButton6Click(event:MouseEvent):void

  {

   addChild(maleDragAndDropBottomsPage);

   removeChild(maleDragAndDropTopsPage);

  }

  function onNextButton7Click(event:MouseEvent):void

  {

   addChild(maleDragAndDropShoesPage);

   removeChild(maleDragAndDropBottomsPage);

  }

  function onNextButton8Click(event:MouseEvent):void

  {

   addChild(maleModelPage);

   removeChild(maleDragAndDropShoesPage);

  }

  function onEditFemaleClick(event:MouseEvent):void

  {

   addChild(femaleDragAndDropPage);

   removeChild(femaleModelPage);

  }

  function onEditMaleClick(event:MouseEvent):void

  {

   addChild(maleDragAndDropTopsPage);

   removeChild(maleModelPage);

  }

  function onSignUpFemaleClick(event:MouseEvent):void

  {

   addChild(mailingListPage);

   removeChild(femaleModelPage);

  }

  function onSignUpMaleClick(event:MouseEvent):void

  {

   addChild(mailingListPage);

   removeChild(maleModelPage);

  }

  function onNextButton9Click(event:MouseEvent):void

  {

   addChild(thankYouPage);

   removeChild(mailingListPage);

  }

  function onFinalHomeButtonClick(event:MouseEvent):void

  {

   addChild(homePage);

   removeChild(thankYouPage);

  }

  function onNextButton3Click(event:MouseEvent):void

  {

   femaleDragAndDropPage.femaleMenu.gotoAndStop(1)

  }

  function onNextButton4Click(event:MouseEvent):void

  {

   femaleDragAndDropPage.femaleMenu.gotoAndStop(2)

  }

  function onNextButtonClick(event:MouseEvent):void

  {

   femaleDragAndDropPage.femaleMenu.gotoAndStop(3)

  } 

  function top1add(event:MouseEvent)

  {

   addChild(strappyTop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top2add(event:MouseEvent)

  {

   addChild(blackLongTop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top3add(event:MouseEvent)

  {

   addChild(pinkTop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top4add(event:MouseEvent)

  {

   addChild(noStraps)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top5add(event:MouseEvent)

  {

   addChild(blacktop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top6add(event:MouseEvent)

  {

   addChild(sequinsTop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top7add(event:MouseEvent)

  {

   addChild(redtop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top8add(event:MouseEvent)

  {

   addChild(vesttop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top9add(event:MouseEvent)

  {

   addChild(pinkShirt)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

  function top10add(event:MouseEvent)

  {

   addChild(greyTop)

   addEventListener(MouseEvent.MOUSE_DOWN,testMouseDown)

  }

 

  private function testMouseUp(event:Event):void

  {

   var currentDragObject:MovieClip = event.currentTarget as MovieClip;

   currentDragObject.stopDrag();

   _isDragging = false;

   currentDragObject.removeEventListener(MouseEvent.MOUSE_UP, testMouseUp);

  

   //Find the name of the object over which the drag object is dropped

  }

  private function testMouseDown(event:Event):void

  {

   var currentDragObject:MovieClip = event.currentTarget as MovieClip;

   currentDragObject.startDrag();

   _isDragging = true;

   currentDragObject.addEventListener(MouseEvent.MOUSE_UP, testMouseUp);

  }

}

}

Ned Murphy
Legend
February 12, 2014

The behavioral issue with the changing of frames is usually a result of the error - the file has a tantrum.

The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....

 

- is declared but not instantiated

- doesn't have an instance name (or the instance name is mispelled)

- does not exist in the frame where that code is trying to talk to it

- is animated into place but is not assigned instance names in every keyframe for it

- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).

 

If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.