I am trying to achieve sort of like an "extender" to a button. I want it to be like a invisible mask, and when you click on it, its the same as clicking on a button directly. Is this possible with an addchild method? Also, if possible, without having to make extra addeventlistners for the mask, so that additional object is seen as that same button. I know it can be done using a simplebutton, but what about a fl.controls button?
You an use either a Sprite or Movieclip as clickable button.
Create both the "button" part and the "mask" part within same MovieClip, and give that whole MC one event listener.
Example if called: myMClip_Button...
myMClip_Button.addEventListener(MouseEvent.CLICK, handler_Mouse_Click );
Later, to access / modify anything within the MovieClip, just use a path:
myMClip_Button.myButton = something;
myMClip_Button.myMask = something;
Related
I have started making an advent calendar using the adobe flash professional software. I have drawn each 'door' individually with the draw tool on separate layers. I need to know how to use action script to wait for a click on one of the doors and then goto a specific layer and stop. I have tried different methods such as
button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
but it throws up errors.
Any ideas would be appreciated.
Thanks
If you drew the door it's still just a vector drawing that you can't really do anything with yet - you'll need to convert it to a MovieClip or a Sprite or a Button. The simple way to do this in the interface is:
Use the pointer to select everything you want to be contained in your MovieClip.
Press F8 OR choose "Modify" from the top menu and then "Convert to Symbol."
From there, you'll get a dialog box that looks like this:
You'll need to give it a name. This name will be the Class Name so call it something like "Door" or something descriptive like that. Leave the type as MovieClip and click "Ok."
Now you have the class so you'll have to give it an instance name. Select the object that you just created on the stage. In your properties it should look something like this:
Where it shows "instance name" delete that and give your object a name. In your code example you called it button so call it button here. Now you have an object that can listen for event listeners. Inside your handler you can write something like this.gotoAndStop(2) to get where you need to go.
Hope this helps!
Why isn't the myMouseClick event being fired?
myMC:TestMC = new TestMC();
myMC.addEventListener(MouseEvent.CLICK, myMouseClick);
addChild(myMC);
function myMouseClick(e:MouseEvent):void {
trace("clicked");
}
As far as I can tell from the tutorials I've seen, that should work. For a moment, I thought that since I was adding the event listener to myMC, I needed to have the event function inside the myMC class, but that didn't work. Just gave an error about accessing an undefined property.
If it helps any, TestMC is a seperate .as file that extends movie clip.
I'm just trying to make it so when the movie clip itself is clicked, it does something. The movie clip itself will be following the mouse.
The object I was trying to click was made up on vertical lines. Apparently the whole movie clip isn't a collider... just the pixels in it, so when I was clicking, I wouldn't hitting enough of it. Changing it to a box worked. I could probably nest it if I wanted the same design, but that's fine.
Is there a way in AS3 to make a the mouse ignore a certain movieclip? I need it to be on top of the other movieclips (due to transparancy effects), but have it in a way that allows clicking on the movieclips underneath it. I know about ".mouseChildren = false", but that only makes all the stuff inside that movieclip unclickable, but it still functions as a "barrier" on top of all the others buttons.
Is there a way to do this, or do I need to remove it completely ?
You need to set both .mouseChildren and .mouseEnabled to false before you can click on objects behind the MovieClip. This makes the mouse ignore the objects within the MovieClip and the MovieClip itself.
Source: http://pixelfumes.blogspot.com/2008/01/clicking-through-movieclips-to.html
EDIT: Oops, didn't see that comment by Alex, sorry.
I really don't know how to explain this problem. I'm really stumped as to what is causing it.
Here is the code:
var abutton:AButton = new AButton; //Where AButton is a button defined in my library
addChildAt(abutton, numChildren);
abutton.addEventListener(MouseEvent.CLICK, attack);
It doesn't want to work when certain movie clips are underneath it, but I don't want to make it more complicated by switching to another screen. Is it possible to make the button work with movieclips underneath?
What do you mean by "certain movieclips"? What do you mean by not working? The CLICK event isn't firing? Normally if a click isn't working on a button, it means that something else it trapping the mouse click above your button. This can be another Sprite, MovieClip or TextField.
Add a click listener to the stage, and have it print out target and currentTarget. Then, when you button doesn't work, the stage listener will still fire and you'll be able to see the object that's blocking your button.
Im doing a program in AS3 and, i'm trying to do the following:
Lets say I have a button, which have onClick event, and when the event is triggered, the popup window will appear.
And in this popup window there is going to be an animation (countdown) of 2020 (this is just an example).
Is there a way to do this without javascript. Because i'm not doing this for website, its going to be a animation.
Hope i was clear.
Thanks
In Flash,create a movie clip, give it an instance name of "countdown_mc", put the countdown animation inside it.This will be your "alert" type window.
Now, in the movieclip containing "countdown_mc", add a new layer and on the same frame bring up the action editor(F9) and write the following: countdown_mc.visible=false;
When you push the button it should make countdown_mc.visible=true and maybe do an optional growing animation;
Also on this frame add a listener for countdown_mc so that when the user clicks on the window it disappears(countdown_mc.visible=false);
For animations add download tweenmax from http://www.greensock.com/tweenmax/, extract the archive in the folder that contains your fla and add the following to your code:
import com.greensock.*;
TweenMax.from(countdown_mc,0.5,{scaleX:0,scaleY:0});