PDA

View Full Version : Need HELP Targeting a Movieclip inside a Scroll pane [AS3]



mnat
December 9th, 2009, 06:49 PM
Hi,

I have been searching for an answer to this and can't seem to find one for AS3:

I have a scroll pane component that dynamically loads a movie clip from my library. This movie clip has buttons inside that I would like to access from my main timeline. I can't figure out what my target path should be (for AS3).

In AS2 it appears that it would be something like this:
scrollpaneName.spContentHolder.inside_btn...

AS3 doesn't recognize spContentHolder though so it must be something different...

Please help!:stare:

Booradley
December 9th, 2009, 07:28 PM
You need to reference the scrollpanes content with:


scrollpaneName.content.inside_btn

you may need to do:


var content :MovieClip = scrollpaneName.content as MovieClip;

mnat
December 9th, 2009, 09:50 PM
Thanks for your help Booradley,

I had tried that before and it didn't work -- I kept getting an error message:

1119: Access of possibly undefined property coffeeA_btn through a reference with static type flash.display:DisplayObject.

mnat
December 9th, 2009, 09:50 PM
Here is my code:


scrollpane.setStyle("contentPadding", 10);
scrollpane.source= drink_names;
var content :MovieClip = scrollpane.content as MovieClip;
scrollpane.content.drinkA_btn.addEventListener(Mou seEvent.CLICK, test);
var i=0;
function test(event:Event) {
i=2;
trace(i);
}


To be clear: drinkA_btn is the instance name for drink1_btn which resides in a movie clip called drink_names. Both the scrollpane and drink_names have been exported for actionscript.

Thanks again for your help.

whodeee
December 14th, 2010, 05:21 PM
I know this is about a year old, but i thought I would post the answer here anyways in case others are looking for it.

what mnat needs to change in the above script is to remove the "scrollpane." from in front of scrollpane.content.drinkA_btn.addEventListener(Mou seEvent.CLICK, test);
in order for it to work.

Hope this helps someone.