ActionScript 3: Jump to a specific frame and target a MovieClip in that frame - actionscript-3

I'm trying to do some stuff in Flash. Let's say I have a MovieClip called mcShape with three frames. In each frame there is a different shape that masks another movie clip, in another layer, that spans for the said three frames. That movie clip is called mcColor and defines the color seen through the shape, thus rendering the desired shape in the desired color:
From the main timeline, on the frame where I have mcShape, I've written the following code:
mcShape.gotoAndStop(some frame);
mcShape.mcColor.gotoAndStop(some other frame);
The thing is this doesn't work. When I don't change mcShape frame, everything works fine, but when I gotoAndStop some other mcShape frame, mcColor is not detected anymore and I get Error #1009: Cannot access a property or method of a null object reference. Even if I put three different frames with a different instance of mcColor on that frame, it doens't work.
Are there any workarounds to this? What am I doing wrong? Thank you very much!

Updating to Adobe Animate seemed to solve the problem.

Related

AS3 movie instance turning null

I'm banging my head on what seems like a simple as3 problem. I have a flash chart that contains a series of buttons that go to different parts of the timeline on Roll_over.
so for example - the "Market maneuvers" button looks like this
marketManeuversButton.addEventListener(MouseEvent.ROLL_OVER, marketManeuversButtonReaction)
and the function it calls looks like this
function marketManeuversButtonReaction (event:MouseEvent):void{ gotoAndStop('18'); }
The problem is, when I mouseover that button (and many others), it goes to frame '18' and then throws this error:
Error #1009 Cannot access a property or method of a null object
reference
here is my flash file
Any help would be appreciated. Thanks.
When you change frame, flash recreated all objects in frame, and you loose all your data.
Yes, it's simple AS3 problem, just don't use a scene frames at all. Program all in classes, don't use any frames to code any logic except stop(), gotoAndStop(), gotoAndPlay().
In your problem, put all scene in movieclip, exclude control buttons from it to another movieclip and control scene movie clip with control movieclip >____<. It pegleg. Next time just do it right, don't use scene frames.

How do I edit a variable declared in the root contained within the frame of a movie clip?

So I have a main scene called Game. In that scene, I have a movieclip called Shop. Inside that movieclip called shop, I have another movie clip called upgradeweapon2. Inside upgradeweapon2, I have a button called "upgradeweaponpb".
I am working in actionscript, in the frame of the movie clip upgradeweapon2. I am trying to edit a variable called "weaponlvl" that was declared in Game. A picture to show what I mean:
http://gyazo.com/96b04ab89ea4a589bee560d53d165b03.png
I am getting the following error: Access of undefined property weaponlvl.
Please tell me there is a way around this... I know weaponlvl is defined in the root scene, game, but is there a way to make the declaration valid across levels of MovieClips, or at least a way to transfer the values accross?
Here is the code I am trying to add:
stop();
upgradepb.addEventListener(MouseEvent.CLICK, upgradeweapon5);
function upgradeweapon5(event:MouseEvent):void{
weaponlvl++;
}
EDIT: Alright I simplified my code, It's just a movieclip, not two layers. But still the same error. Any idea what I can do?
weaponlvl is on the frame of upgradeweapon2.upgradeweaponpb; it is not on the root layer, so therefore in action script it will not make sense. You have two options:
Get weaponlvl through MovieClip(root).weaponlvl or this.parent.parent (which is also the root).

AS3 How can I solve the bug of setChildIndex

I've gathered all game pages on different frames of movieclip called game. in that game movieclip there are 4 different frames. on third frame I have some drag & drop functionality. When I drag one item, I want it to be on the front, I mean all other objects on that frame must not block the view of current dragging object. I used this.setChildIndex(currentDraggingObject,this.numChildren-1); but the problem is whenever I drag objects, when I change the frame, those objects are shown on that frames as well.
In short description: When I set an object's Index in MovieClip(game) , that object is seen in each frame of MovieClip(game) , how can I fix this?
I've searched the result online but couldn't find a solution.
Thank you
-Ozan
Instead of this:
this.setChildIndex(currentDraggingObject,this.numChildren-1);
You can simply use this:
this.addChild(currentDraggingObject); //shorter and clearer
If you have some object on a frame and you actually add it again, it indeed stays there in the other frames (I found this out too). The best/fastest solution would be to simple remove them before you are going to change the frame with this.removeChild(object)

Clip staying on screen while not in timeline anymore

I have a particular problem : I have a fla with 2 frames, with a clip of instance name "my_clip" on frame 1 and no clip en frame 2. If i move by code (like a tween) "my_clip", when I go to frame 2, the clip is still on screen, whereas frame 2 is totally empty in my fla.
How flash work at this level ? Does he stop "syncronizing" a clip with the fla once the clip has been moved by code ? How can I check at frame 2 that the scene should be empty ?
(I'm with flash cs 5.5 and player 11)
Actually what FLASH does when we are trying to change the depth or start drag and some more dynamic functionality it freezes the target movieclip in stage. Eventually there is only one stage in FLASH and guess what if the movieclip has been frozen in the stage? It is visible or available always.
So in your case the same has happened. The clip has just frozen to the stage. Needless to say, the second frame is empty always. You don't need to check the second frame. What all you need to do is remove that clip before you navigates to either next frame or scene.
#LondonDrugs_MediaServices : I can't post my code and fla because there is too much code unrelated to the problem.
But as I was trying to make a little fla to reproduce my problem and show it to you, I figure out that the problem was not where I thought it was : I fact it was because each time I start dragging my clip i was doing a setChildIndex on it to put it on top. And it was precisely the setChildIndex wich would cut the "syncronization" between the clip and the fla timeline.
Thanks anyway for your answers, it kind of help me in a way :)

AS3 preloader sorrows, unable to load symbols from library

I created an AS3 preloader, and placed the code for that on frame one.
I then made a symbol, and placed it in the library. It was set to NOT export on frame 1, and the fla's settings had all classes exported on frame two. There were no references to the object until frame two.
Then, flash crashed whenever I compiled without the "Export in frame one" box checked.
To fix this, a friend suggested I start my game logic on frame 3, so it will have properly loaded frame 2. That seemed to work fine, the class was instantiating properly.
Then, it turned out that it was not loading the movieclip, only instantiating the class. Again, this could be fixed by exporting in frame 1, but I really cannot afford to do that.
The same friend suggested I place an instance of the symbol on the stage on frame 3, and perform game logic on frame 4. They said this would initialize the movieclip properly.
However, this was not the case. How can I load the entire symbol, graphics and all, without exporting to frame 1? This single symbol will contain probably 10-20 MB of graphics, so it needs to be preloaded.
Thanks for the help!
EDIT: To make a long story short, all I need is some way to load a movieclip so it can be used and visible and everything.
EDIT: Is there any way to force-load a movieclip via AS3?
Hard to figure out from descriptions.
If you make a new .fla file, paste your large(10-20MB) clip on frame 2,
set your export frame as 2, then try to preload from frame 1 and access the large clip's content in frame 2, do you get the same error ?
say you have this in frame 1:
stop();
this.loaderInfo.addEventListener(Event.COMPLETE, onComplete);
function onComplete(event:Event):void{
gotoAndStop(2);
}
and in frame 2:
trace(myLargeClip);//where myLargeClip would be your 10-20MB clip
It should be ok, otherwise, in case tracing your large clip returns null, you might want to try to invalidate the stage:
on frame 2:
stage.addEventListener(Event.RENDER,onRender);
stage.invalidate();
function onRender(event:Event):void{
trace(myLargeClip);
}
Basically what I'm suggesting is:
Isolate the problem. See if your large clip is causing problems in a similar, but simplified scenario and why, then once you got a fix use it in your main fla.
Try the stage invalidation, although, since I don't fully understand your setup, it's just a wild guess.
HTH,
George