1 Replies - 21643 Views - Last Post: 23 January 2009 - 03:15 AM

#1 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1651
  • View blog
  • Posts: 8,523
  • Joined: 07-September 06

AS3 calling parent functions from a movieclip

Posted 22 January 2009 - 09:50 PM

Okay, I have this code in root (on the stage, layer 1 frame 1):
var sel:MovieClip;
function changeSelection(mc:MovieClip):void{
	sel = mc;
function updateControls(e:KeyboardEvent):void{
	if(sel != null){
		sel.t.text = String.fromCharCode(e.charCode);
stage.addEventListener(KeyboardEvent.KEY_UP, updateControls);

And this code in a movieclip (which has a dynamic textbox called t and nothing else):
this.s = function(e:MouseEvent):void{
this.addEventListener(MouseEvent.CLICK, this.s);

I am having trouble because the line:

doesn't seem to want to work no matter what I do.

I have tried to use root, MovieClip(this.parent), MovieClip(root), MovieClip(this.stage), this.stage, instead of the current parent that is in the code, and I think that is it, each of which has given me various errors when trying to run the app (as is, nothing else in it).

If there any way for a movieclip to call a function of its parent's in AS3. I know in AS2 it is a simple this._parent.FUNCTION() or something like that, but AS3 doesn't seem to have anything of the sort...

Any help is much appreciated.

Hope that makes sense :)

Is This A Good Question/Topic? 0
  • +

Replies To: AS3 calling parent functions from a movieclip

#2 thehat   User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: AS3 calling parent functions from a movieclip

Posted 23 January 2009 - 03:15 AM

Your problem is the the compiler doesn't know 100% that the parent you refer to is a movieclip. Normally you could fix this by typecasting parent MovieClip(parent), but this doesn't seem to work when the parent is the document root. This link explains it better than I can, and shows how to turn the compiler's strict mode off.

Unfortunately once this is done your code generates another error, but that's life :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1