How to remove a Movie clip from with-init self - actionscript-3

Ok am trying to remove a movie clip from inside its self. I basically telling a button to play a clip, and at the end of the clip I want it to remove the movie clip. I have tried a few different lines of code but telling me it "1120: Access of undefined property Navi_MC"
root.Main_stage.removeChild(Navi_MC);
also
this.Main_stage.removeChild(Navi_MC);
Sorry forgot to add the layers are Object(root).Main_stage.Navi_MC

if (this.parent) { this.parent.removeChild(this); }
Should work.

Related

exception, information=ReferenceError: Error #1056: Cannot create property ground on Main. (FLASH As3)

I have a deep problem which I have encountered.
I am adding a movie clip inside to another movie clip and flash doesn't like this.
What I'm doing is dynamically adding a movieclip to a movieclip that hasn't been added dynamically.
movieclip 1
private var tim:player = new player();
//inside main
tim.addChild(ground);
now ground is an instance name that hasn't been added via code. It's on the stage in flash and it's a movievlip with the instance name ground.
What can I do to fix this please.
Basically I wasn't really understanding As3,
From reading As3 101 - Display Lists I was able to understand that all things like sprites, shapes and movieclips are added to a display list.
In order to have added tim to a parent, that parent would have to be present.
This means that the parent would need to be added to the display list.
addChild(container);
You can see that container is now part of the display list.
This means I can now:
container.addChild(character);
Add the character to the container, and this now becomes a display object container
I can now trace what's in the container.
trace(container.numChildren);
In this container there are 3 childrens, my ground, the player and the enemy :D

As3 (code snippets) change property of object on stage from within another object

I've been searching for the past few hours how to do this but with no luck. First of all I'm new to AS and not sure what to search for.
So here's what I have and what I want to do:The stage has only 1 frame and on the stage I have 1 button (b1), 1 movie clip that is not visible (area) and 1 visible movie clip that is an animation of 20 frames(ani). For the moment when I press button "b1" it will start the movie "ani" (movie is stopped initially) that will stop when it reaches frame 20. Now what I want is when it reaches the last frame to make movie clip "area" visible. Since I am inside "ani" and on frame 20, I cannot use directly area.visible = true; as I would get the error "Access of unidentified property area." What would be the way to access "area"'s properties from within the other object ?
Inside your "ani" MovieClip (at last frame) add the following sentence,
MovieClip(this.parent).area.visible = true;
Here, parent is your main timeline.
(Note: This approach is not recommended).
Instead, use External classes approach. e.g. use Loader class to load animated swf with COMPLETE event and with contentLoaderInfo get swf object and detect for last frame and make area MovieClip visible.
I'm not sure I completely understand everything you said, but I think what you want to do is something like this on your stage where both ani and area have scope :
ani.addEventListener(Event.ENTER_FRAME, frameCheck);
function frameCheck(e:Event):void
{
if (ani.currentFrame == ani.totalFrames)
{
ani.removeEventListener(Event.ENTER_FRAME, frameCheck);
area.visible = true;
}
}
That was just an example of how you could detect ani hitting the last frame and dealing with that appropriately.
You would need to add the event listener EACH TIME the button is pressed.

Flash Action Script 3: drag movie clip issue

I am new to as3. I create a rectangle and convert it to symbol. Then I go into the symbol and create two sliders. Also, I make the symbol draggable.
controlPanel_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragStartF);
controlPanel_mc.addEventListener(MouseEvent.MOUSE_UP, dragEndF);
function dragStartF(e:MouseEvent){
e.currentTarget.startDrag();
}
function dragEndF(e:MouseEvent){
e.currentTarget.stopDrag();
}
It works fine, but I can't use the slider. If I drag the slider, the entire movie clip moved. How can I solve this problem? Cheers!
Without more info on the structure of your FLA-file I assume that controlPanel_mc is the container containing the rectangle[background] and the two sliders.
What it seems like you did in your code was to add event listener to the container, what that means is that "if a click occures anywhere on this object, do the following". Since that clip "owns" the 2 sliders, the sliders will not get any MOUSE_DOWN-events since the parent is always the one handling the event first.
You probably want to convert the background into a symbol and add the eventListeners to that object instead.
bg.addEventListener(MouseEvent.MOUSE_DOWN, onBgClick);
bg.addEventListener(MouseEvent.MOUSE_UP, onBgRelease);
function onBgClick(e:MouseEvent){
controlPanel_mc.startDrag();
}
function onBgRelease(e:MouseEvent){
controlPanel_mc.stopDrag();
}
That should solve your issue :)

dispatchEvent not working in piecemaker 2

i have tried to research this issue, but being a flash newbie i struggle to wade through the terminology...
i am using the piecemaker 2 slider on the landing page of my BudeStrings Dev Site. the slider contains a total of 5 slides; the first is a movie clip containing multiple frames and the following four are animated text clips consisting of only one frame each.
as per instructions i found on the interwebs, i added a keyframe after last frame of the first (multiframe) clip and added the following code:
dispatchEvent(new Event(Event.COMPLETE));
stop();
to stop the clip looping and to enable the autoplay behaviour of the slider. this works absolutely fine with the first (multiframe) movie clip, but when i try to add the same code to the other four (single frame) clips it does not have the desired effect.
these four clips use the following code:
var myString:String = "Sample text "
var myArray:Array = myString.split("");
addEventListener(Event.ENTER_FRAME, frameLooper);
function frameLooper(event:Event):void {
if (myArray.length > 0){
TextField.appendText(myArray.shift())­;
}
else {
removeEventListener(Event.ENTER_FRAME, frameLooper);
}
}
to display some text with an animated typing effect. if i add a keyframe with the dispatchEvent code as i did on the first clip it stops working and when i append the dispatchEvent code to the above actionscript it has no effect, and piecemaker 2 stops autoplaying when it hits slide number 2.
beyond that i have no idea what is causing the problem. please help.
regards, jan
First of all, you should use the appendText method on a textfield instance, not the class itself (the compiler should give you an error). So if the textfield on your stage is called 'txt' it would become 'txt.appendText..'. Secondly, you should define the event dispatching within the else section as at the time it runs, your animation would be completed.
[edit] make sure you enable strict mode in your publish settings

MoveClip.Visible and MouseEvent - ActionScript3

Say I have the following;
public function onBellyPatch_Two(e:MouseEvent):void
{
inBelly_Two.visible = true;
}
inBelly_Two is a MovieClip
I have two movieclips over top of each other, when you click one MovieClip another one shows up on top, and when you click that (second MovieClip)a textBox is updated.
I noticed that even if a movieclip object's visible property is false, when you click in the area where the movie clip is the MouseEvent.CLICK event is called. Is there a way to get around this? I would like to stack movieClip.
I guess one way to get around this problem would be:
removing the eventListener when movieClip is not visible and enabling the eventListener when moviclip is visible.
Is there some otherway?
Much Thanks,
Mike
Try adding:
inBelly_Two.buttonMode = false;
This will let onBellyPatch_Two be called no matter if inBelly_Two is visible or not.
Instead of removing the listener, you can just say
mc.mouseEnabled = false;
mouseEnabled docs