hiding multiple movie clips - actionscript-3

i'm following this tutorial http://workflowflash.com/3901/hiding-movie-clips-in-as3.php for hide and show movie clips, but i want to hide and show multiple movie clips using one button.
i'm making a simple animation(movie clips) with bubbles text(movie clip). so i want to hide all bubble text when i click disable dialog button. - hide movie clips inside a movie clip. should i use array?
i'm really new to this, so i hope someone can help me and i really appreciate it. :)

Sure, you can use array, but is it a best way - it depends on many things.
Maybe try something like that:
var myArray:Array = [myMoveclip1, myMoveclip2, myMoveclip3];
switchBtn.addEventListener(MouseEvent.CLICK, _switch);
private function _switch(e:MouseEvent) : void {
for each(var item:MovieClip in myArray) {
item.visible = !item.visible; // or just "item.visible = false;" to only hide
}
}
Now your button will be hiding and showing MovieClips from array, but I'm not sure if that is what you expect/need.

Related

How do I change the size of a movieclip in flash by clicking on it? (Actionscript 3)

Everything I've found is for making a separate button, but I'm trying to make it so that clicking on the movieclip itself makes it change size. The reason is that it's being animated moving across the page, so clicking it is the challenge. Can anyone help? This is the code I tried:
info_btn_mc.buttonMode = true;
info_btn_mc.addEventListener(MouseEvent.CLICK, openInfo);
stop();
function openInfo(e:MouseEvent):void {
enemy_first.play("shrink");
}
You cannot use play("shrink"), the method
play() (Moves the playhead in the timeline of the movie clip) has no arguments. use gotoAndPlay/gotoAndStop instead that received an argument called frame:Object (frame number or label (String).
enemy_first.addEventListener(MouseEvent.CLICK, openInfo);
enemy_first.stop();
function openInfo(event:MouseEvent):void
{
trace('event.currentTarget:', event.currentTarget);
event.currentTarget.gotoAndPlay("shrink");
}

add even-listener to a button on timeline that is a grand child of a movie clip

I got a simple flash scene that contain movie clip that contain sliding button that changing every few seconds:
every layer contain a button and another movie clip.
If I want to add event-listener to a simple button on stage, i just write:
f4.addEventListener(MouseEvent.CLICK, f4Click);
function f4Click(event:MouseEvent):void
{
flash.external.ExternalInterface.call("dlHTCMD", "switchtogame?code=fnf50");
}
but when I'm trying to access the button inside the two movie clips, like
optContainer.optBeach.btnBeach.addEventListener(MouseEvent.CLICK, btnBeachClick);
and I'm adding a trace function to see if the event are triggered but nothing is happening.
looks like a simple problem but i didn't find a solution.
I thought about extending the button class and add a bind function with the value as the name of the button and set the Event Listener but I'm not an AS3 expert :(
Thanks.
Try this:
// Pass mouse events to children
optContainer.mouseChildren = true;
optContainer.optBeach.mouseChildren = true;
// Reset hit area
optContainer.hitArea = null;
optContainer.optBeach.hitArea = null;
// Reset masks
optContainer.mask= null;
optContainer.optBeach.mask= null;
Also check whether on each key frame button have name.

Flash AS3 Multi touch event handler

I have 3 separate movie clips in a frame, each clip can be moved around the stage using a simple touch and drag event, which is shown below, incase it has some relevance. I want to drag each of the three clips onto a fourth clip and when all 3 are contained within the fourth clip I want an event triggered that changes the current frame. What is the easiest way of doing this in AS3 ? Any examples would be great as I am a complete beginner. Thanks
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
Gem1_MC.addEventListener(TouchEvent.TOUCH_BEGIN, fl_TouchBeginHandler_2);
Gem1_MC.addEventListener(TouchEvent.TOUCH_END, fl_TouchEndHandler_2);
var fl_DragBounds_2:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
function fl_TouchBeginHandler_2(event:TouchEvent):void
{
event.target.startTouchDrag(event.touchPointID, false, fl_DragBounds_2);
}
function fl_TouchEndHandler_2(event:TouchEvent):void
{
event.target.stopTouchDrag(event.touchPointID);
}
In the future you'd want to implement a solution where your drag and drop functionality is abstracted into a class but to work with what you've got, here's a basic solution:
Keep track of when the three MovieClips are considered "contained within" the fourth clip
var contained:Array = new Array(false, false, false);
In the event of an object finishing it's drag, check to see if it's contained in mc1. At the end of these checks, find out if they're all true:
function fl_TouchEndHandler_2(event:TouchEvent):void {
// Drag & drop stuff...
contained[2] = Gem2_MC.hitTestObject(Gem4_MC)); // where Gem4_MC is your 4th movie clip.
if (contained.indexOf(false) == -1) { // This returns -1 if it can't find false
gotoAndStop(frame_number_you_want);
}
}
As a side note, hitTestObject() uses a simple "bounding box" to dectect "collision". This means it may register a hit as true even when two movie clips don't look like they're actually touching. Pixel perfect collision detection in Flash is possible but more complicated and worth its own post. A simple example of pixel perfect collision in AS3 can be found here.

currentFrame identifiers [AS3]

I'm completely new to Flash and AS3, and I'd have thought this would be a simple question, but I've been unable to find an answer online or in the documentation. I'm trying to use addEventListener (Event.ENTER_FRAME) and (.currentFrame) to disable a button for part of an animation sequence. While the animation sequence fades in, the Button Hand cursor is visible and people can select it before the sequence is completed. I want this button disabled for the first 213frames of the main timeline, which is when the button becomes visible.
Earlier, I was successfully able to disable a Rewind button for parts of a different movie scene using the code below with a few insignificant things changed.
Skip_btn.addEventListener(MouseEvent.CLICK, SkipToGoToScene);
function SkipToGoToScene(event:MouseEvent):void
{
MovieClip(this.root).gotoAndPlay(1, "Opening");
}
//Skip_btn functions
Skip_btn.addEventListener(Event.ENTER_FRAME, skipDisable);
function skipDisable(event:Event) {
if (this.currentFrame < 213)
{ Skip_btn.mouseEnabled = false;
} else {
Skip_btn.mouseEnabled = true;
}
if (this.currentFrame > 213) {
Skip_btn.removeEventListener(Event.ENTER_FRAME, skipDisable);
}
}
The problem is that before I could just use "this.currentFrame" as the button was on the same timeline that it controlled, whereas now it's embedded in a MovieClip that is on the main timeline. What can I swap "this" for so I can reference this main timeline? Also, could someone fill me in on what the other "identifiers" are for ".currentFrame", as I'm not too sure how it works. The documentation examples ask for Movieclips such as "MyMovie_mc.currentFrame", but what if you just want to reference a main timeline?
If the button is on main timeline you could just use
this.root.getChildByName("Skip_btn").mouseEnabled = true;
And if you start playing animation on main timeline use
MovieClip(this.root).currentFrame

actionscript 3 event.target

I have a movie clip named button1 and in this movie clip
there is a dynamic text named txt
public function mouse_down(event:MouseEvent)
{
if(event.target==button1)
{
...//this only recognizes when i click the button without intersecting the dynamic text area
}
if(event.target==button1||event.target==button1.txt)
{
...//this works
}
i would like to know why it dosen't recognize clicks made in the area that contains the dynamic click if i don't specify it, because txt is part of button1, so normally i would only need to check if the target is button1 but it dosen't work:i also have to check if the target is button1.txt
Thanks for your help!
event.target always points to the object the event originated from, even if it is nested in the object you added the listener to. Use event.currentTarget instead.
Check out this blog post to learn more.