-
Help with attach script to button component
Hi,
Can anyone help me out by telling me what the code for something like:
myButton.onMouseDown = function() { _parent.doMouseDown(this); }
becomes when I want to attach the action to a pushbutton component?
I have trued such things as:
myButton.on(click) = function() { _parent.doMouseDown(this); }
but doesn't work.
Thanks in advance.
If it ain't broke, don't fix it.
-
Senior Member
dont really understand the post.
are you trying to subscribe event listeners to the button?
pass the reference to the button that is clicked to another method in its parent?
??
sprout
"If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea."
from The Zen of Python (by Tim Peters)
-
Hi Sprout,
What I am doing is loading in a .swf file. In this .swf file I have a pushbutton component. When I load the .swf into the parent movie, I want to assign a click event to the button, which will fire an event which will be caught in the parent movie.
Hope this makes sense.
Thanks
GW
If it ain't broke, don't fix it.
-
Senior Member
once the movie has loaded into its parent, have the parent movie assign an event listener to the button. Then the parent movie can be the subscriber to the mouse events.
check out the Help files that ship with Flash MX.
There are nice examples of how to use event listeners there.
Then you can have the parent receive the events from the button in the loaded SWF.
ok?
"If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea."
from The Zen of Python (by Tim Peters)
-
Thanks for your help Sprout - still only getting started with Actionscript since version 4!
If it ain't broke, don't fix it.
-
Senior Member
here is a tutorial i found that is an introduction to event objects.
and another one
the idea is that the thing that triggers the event, like a mouse button, tells other MovieClips/objects that the event has occured and then they can react to it if they want to.
it is an excellent way to handle events in Flash.
So, once you know the path to the button that is loaded, once it is loaded, the main movie adds a listener to the button in the loaded clip, so that when it is clicked, the main movie is told about the event.
have a go,
sprout
"If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea."
from The Zen of Python (by Tim Peters)
-
Sprout, thanks again for links to the tutorials.
I have completed a couple of the tutorials and tried an adaptation for the button component.
I have added a pushbutton component on one layer of my flash movie. I have also added the following script:
[actionscript]//butt1.text = "initial content";
myListener = new Object();
myListener.onClick = function() {
trace("clicked button");
};
butt.addListener(myListener);
stop();[/actionscript]
My button instance name is 'butt'. However when I compile the movie and run it nothing happens.
Any ideas?
Thanks in advance.
If it ain't broke, don't fix it.
-
Senior Member
i think you have to pass an event object as a parameter of your
function.
Code:
myListener = new Object();
myListener.onClick = function(oObject) {
trace("clicked button");
for (var v in oObject) {
trace (" v: " + v + " oObject[v]: " + oObject[v]);
}
};
butt.addListener(myListener);
stop();
The 'for' loop is just to show what kind of properties are passed in in the oObject parameter.
"If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea."
from The Zen of Python (by Tim Peters)
-
Sprout,
Thanks for the quick reply, but it still wont work.
GW
If it ain't broke, don't fix it.
-
Sprout - managed a simpler solution:
code: butt.onPress=function(){
trace("Our button was pressed");
}
Doesn't use listener, but works! I think I'll get a good book on AS 2 / listeners.
Thanks.
If it ain't broke, don't fix it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|