Reference a MovieClip symbol later on in the timeline

旧巷老猫 提交于 2019-12-13 21:16:49

问题


I've been trying to reference a Library symbol that is introduced in Frame 2 by using it's instance name, using timeline scripting only.

I am trying to make a colour picker MC symbol for multiple re-use. Firstly I drew a small button on the stage and converted to MC, called textColourPicker of type CPicker (the class used to represent this MC in the Library). Inside this MC I have a button symbol called pickerButton

In the first frame of textColourPicker MC, I placed the code:

stop();
pickerButton.addEventListener(MouseEvent.CLICK, doShowPicker);

function doShowPicker(e:MouseEvent):void
{
    gotoAndPlay(2);

}

In Frame 2 of the textColourPicker instance, a new MC appears with instance name pickerBox of type pickerBMP. The pickerBox is then scale tweened until Frame 14 at which point I have the code:

stop();
pickerBox.addEventListener(MouseEvent.MOUSE_OVER, cursorToColour);

Except I always get the error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at CPicker/frame14()[CPicker::frame14:10]

Here CPicker is referring to the Linkage name of the textColourPicker MC.

So textColourPicker is Instance of: myPicker, linkage name: CPicker

and pickerBox is instance of: pickerBMP, linkage name: pickerBMP (residing inside the textColourPicker MC.

Why is not allowing me to reference the pickerBox MC on Frame 14 of the textColourPicker?

This graphic of the textColourPicker timeline may help illustrate all this (note the two timeline scripting icons, first in Frame 1 last in Frame 14:


回答1:


I wrote a post for InsideRIA about doing exactly what you are trying to do. It is archived here:

http://www.developria.com/2010/04/combining-the-timeline-with-oo.html

It seems to me that your best bet is the getter/setter method, since you have a keyframe at the end where a new value will be inserted into the variable's value.

Example code for both methods is available here http://flexdiary.blogspot.com/2010/04/sample-code-for-oop-timeline-insideria.html

HTH;

Amy



来源:https://stackoverflow.com/questions/6792291/reference-a-movieclip-symbol-later-on-in-the-timeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!