View Full Version : Why does this work / not work?
davec
August 27th, 2009, 04:30 PM
I have a 10 frame movieClip which I can put on the timeline in a new movie like this:
var impPanel:MovieClip = new ImpPanel();
addChild(impPanel);
var btn:SimpleButton = new TBtn();
btn.addEventListener(MouseEvent.MOUSE_UP, setFrame);
addChild(btn);
function setFrame(myFrame:String):void {
myFrame = "i4";
impPanel.goto(myFrame);
}
the impPanel clip contains the function:
function goto(val:String):void{
gotoAndStop(val);
hideStuff();
}
so sending the variable myFrame to impPanel changes the frame in the clip and hides some subclips. This all works fine.
However if I do the same thing in a more populated FLA (impPanel is one of 6 objects on the stage), I get the following: 1120: Access of undefined property impPanel..
Any idea why this should be happening?
snickelfritz
August 27th, 2009, 05:00 PM
I don't see how the setFrame function could work with anything other than impPanel, since impPanel is directly targeted by name, and the String value for myFrame is set directly as String (as opposed to assigning the String dynamically to a variable) within the function.
Write the function to be reusable.
ie: generic; not specific to any particular object or value.
Also, I question the general practice of nesting AS3 within MovieClips on the stage.
This might have been a normal practice with AS2, but it's definitely outside the norm for AS3.
I'm not surprised that you're having trouble with this setup, but it's hard to say why it's occurring.
Post the zipped FLA.
davec
August 27th, 2009, 05:08 PM
I'll take your point about the code, but problem doesn't appear to be with the function, as the error arises as soon as the FLA is compiled, and will occur even if the function is remmed out.
It just seems that although the impPanel clip has been created and is sitting on the stage, it's not identifiable by code.
IQAndreas
August 27th, 2009, 06:29 PM
However if I do the same thing in a more populated FLA (impPanel is one of 6 objects on the stage), I get the following: 1120: Access of undefined property impPanel..
So in that case, impPanel is added to the stage using the IDE instead of code, correct?
Did you make sure to name the instance name "impPanel", and not just name it that in the library? See attached image of where you should put the instance name.
davec
August 27th, 2009, 06:38 PM
So in that case, impPanel is added to the stage using the IDE instead of code, correct?
Did you make sure to name the instance name "impPanel", and not just name it that in the library? See attached image of where you should put the instance name.
No, it's added using code, and the error occurs regardless of whether you actually give the instance a name in the code or not; i.e. "impPanel.name = "impPanel".
I can see why you might think it's loaded via the IDE - I created the impPanel clip in the IDE of a new FLA and then copied and pasted the frames into a new Symbol in the main FLA.
I've also tried using 'bodyPanel' as the instance name and object, i.e.
'var bodyPanel:ImpPanel = new ImpPanel();'
or
'var impPanel:ImpPanel = new ImpPanel();
impPanel.name = "bodyPanel";'
same result... ;(
snickelfritz
August 27th, 2009, 07:40 PM
Push the MovieClips into an array.
You can then access them as Movieclips at a given index.
An instance name is not required.
>
Usually, an XMLList is used to organize Flash projects.
This essentially pushes all of the data for the structure of your site into a set of arrays, which executes very fast, and facilitates more efficient coding practices.
BTW, instance names/frame labels are very useful for some things, such as targeting children nested within instances of DisplayObjectContainers, ( a textfield label within a MovieClip or Sprite, for example) but are not generally an efficient method on which to base your overall site architecture.
This is because instance name lookups are relatively SLOW, and this method is, by its very nature, more susceptible to developer errors (spelling errors, omissions, etc...), and is generally a lot more work to construct/update/maintain.
davec
August 27th, 2009, 11:04 PM
Push the MovieClips into an array.
You can then access them as Movieclips at a given index.
An instance name is not required.
>
Usually, an XMLList is used to organize Flash projects.
This essentially pushes all of the data for the structure of your site into a set of arrays, which executes very fast, and facilitates more efficient coding practices.
BTW, instance names/frame labels are very useful for some things, such as targeting children nested within instances of DisplayObjectContainers, ( a textfield label within a MovieClip or Sprite, for example) but are not generally an efficient method on which to base your overall site architecture.
I understand the XML, but I don't know how you would push the clips into an array. Is there example code somewhere that you could point me to?
davec
August 29th, 2009, 02:57 AM
I found the info on putting clips in array and it worked perfectly in isolation, but still wouldn't work in the main program.
I eventually solved the problem by using adding the eventListeners and the gotoAndStop() to the clip before adding it to the stage.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.