Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Thread Tools Rate Thread Display Modes
Old 04-28-2012, 01:59 AM   #1
Registered User
Join Date: Dec 2010
Posts: 22
Default TypeError: Error #1007: Instantiation attempted on a non-constructor.

Hi guys, having a problem with a project I'm trying to convert a project from As2 to As3. This particular section of code is supposed to create a dynamic drop down menu. I keep getting this error:

TypeError: Error #1007: Instantiation attempted on a non-constructor.
	at experiment_2_fla::MainTimeline/frame1()
ActionScript Code:
var menuButtons:Array = ["Male OPM", "Female OPM", "Male Foreign", "Female Foreign"]; var subMenu1:Array = ["Sponge Cola - Nakapagtataka"]; var subMenu2:Array = ["Kyla - I Don't Have the Heart"]; var subMenu3:Array = ["Nelly - The Champ", "Jason Mraz - I Won't Give Up"]; var subMenu4:Array = ["Adelle - Someone Like You"]; var chosenMenu:Array = new Array(); var subMenuOpened:Boolean = false; var whichSubMenu:Number = new Number(); var currentPosition:Number = new Number(); var i:int = 0; var j:int = 0; var k:int = 0; var l:int = 0; for (i=0; i<menuButtons.length; i++) {     var menuButton:MovieClip = new "menu button"();     stage.addChild(menuButton+i);     this[menuButton+i].x = 351;     this[menuButton+i].y = 42 +(23*i);     this[menuButton+i].label_txt.text = menuButtons[i];     var mainMenuColor:ColorTransform = new ColorTransform();     mainMenuColor.color = (0xFFCC00);     this[menuButton+i].bkgColor_mc.transform.ColorTransform = mainMenuColor;     this[menuButton+i].onRollOver = function():void {         whichSubMenu = Number(this.name.substr(-1, 1));         currentPosition = this.x;         if (!subMenuOpened) {             subMenuOpened = true;         openSubMenu(whichSubMenu, currentPosition);         } else {             parent.removeChild(this);             openSubMenu(whichSubMenu, currentPosition);         }     }; } function openSubMenu(whichSubMenu, currentPosition):void {     chosenMenu = this["subMenu"+whichSubMenu+1];     for (j=0; j<chosenMenu.length; j++) {         var subMenuHolder_mc:MovieClip = new MovieClip();         stage.addChild(subMenuHolder_mc);         var subMenuButton:MovieClip = new "menu button"();         subMenuHolder_mc.addChild(subMenuButton);         subMenuHolder_mc[subMenuButton+j].x = currentPosition+178;         subMenuHolder_mc[subMenuButton+j].y = 42+(j*23);         subMenuHolder_mc[subMenuButton+j].label_txt.text = chosenMenu[j];         var subMenuStartColor:ColorTransform = new ColorTransform();         subMenuStartColor.color = (0xFF00FF);         subMenuHolder_mc[subMenuButton+j].bkgColor_mc.transform.ColorTransform = subMenuStartColor;         subMenuHolder_mc[subMenuButton+j].onRelease = subMenuHolder_mc[subMenuButton+j].onReleaseOutside=function ():void {             this._parent._parent.Karaoke.gotoAndStop(this.label_txt.text);             parent.removeChild(subMenuHolder_mc);         };         subMenuHolder_mc[subMenuButton+j].onRollOver = function():void {     var subMenuRollOverColor:ColorTransform = new ColorTransform();     subMenuRollOverColor.color = (0xFF6600);     this.bkgColor_mc.transform.ColorTransform = subMenuRollOverColor; }; subMenuHolder_mc[subMenuButton+j].onRollOut = function():void {     var subMenuRollOutColor:ColorTransform = new ColorTransform();     subMenuRollOutColor.color = (0xFF00FF);     this.bkgColor_mc.transform.ColorTransform = subMenuRollOutColor; }; } }

Anybody have any ideas? I have a sneaking suspicion it has something to do with me using "menu button" as a class (in AS2 I used the linkage property to access the MC via menu button, I'm assuming it's the same in AS3.)

Last edited by grayle; 04-28-2012 at 05:08 AM.
grayle is offline   Reply With Quote
Old 04-28-2012, 07:45 AM   #2
Holosuit User
wvxvw's Avatar
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,669
Send a message via ICQ to wvxvw

ActionScript Code:
new "menu button"();
Did this ever work? I didn't know you could do things like that in AS2 This is the place that generates the error, but there will be more things you will need to fix too. The event model is different (no more onRelease / onRollOut etc.).
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw is offline   Reply With Quote
Old 04-28-2012, 07:54 AM   #3
Registered User
Join Date: Dec 2010
Posts: 22

Thanks for the reply wvxvw! Yeah, it used to work in AS2, but the format it had was:

ActionScript Code:
this.attachMovie("menu button", "menuButton"+i, this.getNextHighestDepth());

but since As3 got rid of attachmovie and getnexthighestdepth, I had to reformat it to it's current incarnation:

ActionScript Code:
var menuButton:MovieClip = new "menu button"();     stage.addChild(menuButton+i);

Did I translate it wrong? I assumed it was correct since I didn't get any errors at runtime. But this output error has me pacing the walls and ceiling!

Thanks for the heads up on the onRelease and Rollout thing, it'll give me a quick distraction before I have to come back to solving this problem again.
grayle is offline   Reply With Quote
Old 04-28-2012, 12:10 PM   #4
Senior Member
henke37's Avatar
Join Date: Mar 2009
Location: Sweden
Posts: 11,061
Send a message via Skype™ to henke37

The new operator requires a Class, not a String. Since the symbol doesn't even change, you should just use the class name you set in the symbol properties dialog (no quotes) and be done with it.

It is considered poor practice to add items directly to the stage for no good reason. Please think twice about where in the display tree you want to add the object.
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 02:36 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.