Trying to access another MovieClip on frame 2 of a movieclip on main timeline

Multi tool use
Multi tool use


Trying to access another MovieClip on frame 2 of a movieclip on main timeline



I am working with nesting of movieclips.



I am trying to access another movieclip in frame 2 of main movieclip on stage.



=> test2 movieclip is present on frame2 of test movieclip.



I am getting this error because of accessing test2 variable..



TypeError: Error #1009: Cannot access a property or method of a null
object reference. at Untitled_fla::MainTimeline/Access() at
Untitled_fla::MainTimeline/Untitled_fla::frame1()



Any alternate method to access test2 movieclip on frame2 of main movieclip?



My Code is :


var test1:MovieClip;
var test2:MovieClip;
test.stop();

function Start(){
//test.addChild(test1);
//Test1 = new test1();
//Test2 = new test2();
trace(test.numChildren);
test1 = MovieClip(test.getChildByName("test1"));
test.gotoAndStop(2);
test2 = MovieClip(test.getChildByName("test2"));

}
function Access(color:String){
var r:RegExp=new RegExp(/#/);
var uintColor:uint = uint(String(color).replace(r,"0x"));
var c: ColorTransform = new ColorTransform();
c.alphaMultiplier = 0.9;
c.color = uintColor;
test.gotoAndPlay(2);
test2.transform.colorTransform = c;
}
Start();
Access("#666666");





right now you're just informing us that you do that. what is your question? what are your issues? what is happening and what should happen?
– andr
Jan 30 '13 at 9:41





> I am getting this error... TypeError: Error #1009: Cannot access a property or method of a null object reference. at Untitled_fla::MainTimeline/Access() at Untitled_fla::MainTimeline/Untitled_fla::frame1()
– Abhijeet Goel
Jan 30 '13 at 9:44






it means one of your variables is null. Most probably it's the test or test2 variable. you must assign a value to a variable before using it.
– andr
Jan 30 '13 at 10:12


null


test


test2




2 Answers
2



In flash while moving though he timeline flash player creates the nested children only in the end of frame (except the first frame) that is, if you have child named test2 in he second frame of clip and navigate to this frame you have to wait 1 frame before the children in this 2nd frame will be creared. Try the following solution:


test2


clip


function Start(){
trace(test.numChildren);
test1 = MovieClip(test.getChildByName("test1"));
test.gotoAndStop(2);
addEventListener(Event.ENTER_FRAME, function(event:Event):void
{
EventDispatcher(event.target).removeEventListener(event.type, arguments.callee);
test2 = MovieClip(test.getChildByName("test2"));
});
}





Awesome.. It worked.... :) Thanks..
– Abhijeet Goel
Jan 30 '13 at 10:37



Try changing your Access function. I think test2 wont be available if you are playing test MovieClip.


function Access(color:String){
var r:RegExp=new RegExp(/#/);
var uintColor:uint = uint(String(color).replace(r,"0x"));
var c: ColorTransform = new ColorTransform();
c.alphaMultiplier = 0.9;
c.color = uintColor;
test.gotoAndStop(2);
test2.transform.colorTransform = c;
}






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

6pM,oSZ,rG2
DwAN,RDj9Jm ScHNkZxOzgl8aP1DjDqpqO,EUTn

Popular posts from this blog

Rothschild family

Cinema of Italy