ActionScript 3.0 :: Calling MouseEvent From Within A Different Function
Jan 19, 2012I've got a mouse event that I need to call from a function within the mouse event function, but I'm getting an error.[code]
View 5 RepliesI've got a mouse event that I need to call from a function within the mouse event function, but I'm getting an error.[code]
View 5 RepliesI've got a mouse event that I need to call from a function within the mouse event function, but I'm getting an error. Here's the code I'm using:
function onTrButtonClick(me:MouseEvent):void
{
trace ("Do something");
[code].....
in actionscript 2.0, one could call a mouseEvent function without actually having that event. For instance:
btn1.onRollOut = function(){
this. gotoAndPlay("out");
}
[code]......
I want to run it when the user mouses over a hidden button.
Code:
var container:MovieClip = new MovieClip();
addChild(container);
root.transform.perspectiveProjection.fieldOfView = 120;
[Code]....
You can see I have a MC called "btn" but the code only runs once when the btn MC is moused over. I'd like to call the addstar function continously while the btn is being moused over...
in actionscript 2.0, one could call a mouseEvent function without actually having that event. For instance:
[Code]...
In this example, of course, rollOutHandler only does one thing, but this function could contain lots and lots of code, and I would not want to repeat all of it again inside the clickHandler function.
I am working with AS3 to build a very simple mp3 player on my site. So far the play and pause button work fine, but when I try to move the slider then click the pause button, it doesn't pause, and then clicking the play button again causes it to play a new file.I'm assuming that for some reason when I call the playMp3 function from my MouseEvent, it's within an object or something and not at the root, so it's like loading a new sound file, but I don't know how to fix that.URL...
View 2 RepliesI currently have an AS3 fla with a couple of mouseEvent functions but now the client wants to add a KeyboardEvent as well to the same exact functions. Can I add another eventListener to that without having to create a second function? It would be a huge waste of code if I did. Here's what I currently have in truncated form:
rightArrow.addEventListener(MouseEvent.CLICK, slide_right);
leftArrow.addEventListener(MouseEvent.CLICK, slide_left);
function slide_right(e:MouseEvent):void {
[code]....
I have some functions that have mouseEvents for their param and I am wondering how those can be use without the param. Meaning those functions where set up to work with buttons, but how can call those when I don't have a button to call them? Here is an example of one of the functions:
function forward(e:MouseEvent):void
{
ns.togglePause();
[Code].....
I would like to retrieve a value from a function(e.MouseEvent)?
[Code]...
When not, which solutions does replace this attempt?
I made a login (textfield and a button).
mybutton.addEventListener(MouseEvent.CLICK,loginCheck); // This is my button
function loginCheck(event:MouseEvent):void { // My function code here
}
In order to make login using Enter button, I tried adding:
[Code].....
But of course it won't works because loginCheck is a MouseEvent function.
How do i pass the e:MouseEvent to another function??
[Code]...
Is there any way to call MouseEvent function in as3 from JavaScript?I have HTML button and swf object, I need to sent a POST request from swf by clicking on HTML button.
View 1 RepliesI'm sure this must have been covered 100's of times but I have searched and searched with no joy so... I'm trying to simply pass a value into a function using a MouseEvent, CLICK (the example below is just that an example not what I'm actually trying to do)[code]...
View 4 Repliesi am making drag drop game.i create some movie clips dynamic.
this is the code::
recipesArray=["Steak","Chicken Panee","Bread","Fava Beans", "Jam"];
/////Create Movieclips && set their text
[code].....
I am trying to make a simple mp3 player using flash. The songs are loaded using an XML file which contains the song list. I have "play" button with the instance name "PlayBtn". I have an actionscript file named "playctrl", the content of which are listed below:
package classes
{
import flash.media.Sound;
[Code].....
However on clicking the play button, I notice that the function playSong() is called 7-8 times(check by printing an error msg. inside the function) resulting in overlapped audio output and the player crashing as a result. The function should be called only once when the MouseEvent.CLICK is triggered.
I've dynamically created a grid of buttons which are going to modify a 2D array, but I can't work out how to create a unique function for each iteration of the loop with a dynamic function name. Probably just a stupid syntax error by me...
ActionScript Code:
for(var i:int = 0; i < 8; i++){
for(var j:int = 0; j <
[code].....
After parsing some XML to create a vertical project list I'd like to be able to click on the image/icon representing each project and be taken to the URL that's been parsed in as well. Here's the error I get when clicking the dynamically generated Movieclips:TypeError: Error #1009: Cannot access a property or method of a null object reference.at NMD_work_fla::MainTimeline/itemClick()Below is the extracted code pieces related to the onClick function:
//Sample XML:
HTML Code:
<Projects>
[code]......
This will work:
Code:
addVolvo.addEventListener(MouseEvent.CLICK, addCar);
function addCar(evt:MouseEvent)
{
[code]...
... but I want to pass the a value when calling the function:
Code:
addVolvo.addEventListener(MouseEvent.CLICK, addCar(classVolvo));
function addCar(evt:MouseEvent, newClass:Class)
{
var car1:Car = new Car( 1, 1, classVolvo)
[code]...
This won't work. Because it then just passes the Class and not the MouseEvent. What should I write in the addCar(...) call function? Ie how to I manually pass an MouseEvent?
I've done some coding in AS2 and have been trying to make the transition into AS3, but I'm having trouble with a simple piece of code. I've appropriated and slightly altered the majority of this code from an Actionscript 3.0 tutorial that I'm following, but it doesn't work correctly. The main timeline has the following code. The idea is to create a series of movieclips that can be individually clicked to change their current frame.
[Code]....
I have several stage event handlers to enable mouseovers over several dynamically generated moviecilps on the stage that then change their alpha to indicate the mouse is over that particular mc... fairly trivial (mcOver handler). Additionally, I also want to know what MC is clicked, so I update a public variable (public var activemc:Number) with the ID of the dynamic movieclip when the mouse is over it (using a hitTest to check, which is why the EventListener is added to stage and not to the MC), which is checked in the mcClicked handler:This is in the constructor:
//stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
//stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mcOver);[code]....
However, the mouseover behaviour (alpha 0 when over, alpha 1 when out) stops working as soon as I click on any movieclip on the stage, and the mcClicked ID checking (below) stops working completely. I don't know if this is to do with focus:
private function mcClicked(event:MouseEvent):void {
myTextField.text = String(activemc); // activemc is a public var:Number with the movieclip //ID
}
I then tried adding the event handler for the stage mouse_move again and this gets the mouseover working again but only for 1 more click, after which it stops again:
private function mcClicked(event:MouseEvent):void {
myTextField.text = String(activemc); // activemc is a public var:Number with the movieclip //ID
stage.addEventListener(MouseEvent.MOUSE_MOVE, mcOver);
I have a MovieClip (call it base_mc) which is under a bunch of other MovieClips (call them subclips). The MovieClips on top are all mouseEnabled with MOUSE_OVER, CLICK, etc, event handlers. I want to capture the event of MOUSE_OVER (or ROLL_OVER) on the base_mc as well. Any time I am over one of the subclips I am also over the base_mc clip. How can I capture this event?
View 2 RepliesI've got an image gallery, that when the the image is clicked, it opens 2 images side by side like a magazine. Once the 2 images are loaded and visible, it makes visible 2 movieclips on each side to let you go to either the previous/next 2 images. Here's my code, I made bold the code that specifically relates to my problem. What I'm trying to do is when the button is clicked it either increases or decreases the imgCount by 2, and reloads the new images, but since the function I'm trying to initiate is triggered by a mouse event I don't know how to trigger it when the other function is triggered.
var imgCount:int = 1;
var imgLoader:Loader;
var lLoader:Loader;
[Code].....
I hv make 4 movieclips and i wanna add mouse event but it is showing error on MouseEvent function, and the error is. 1046: Type was not found or was not a compile-time constant: MouseEvent.
[Code]...
I am having a small problem in regards to a click and drag interface I am trying to create.
The user should be able to drag objects around the stage and when desired click to preform an animation.
The problem is that the click to initiate the drag also initiates the click of the animation to play.
I don't really want to make one of the commands a double click as that may feel clunky to some users.
Is there any way to cancel the animation click if the user moves the mouse before letting go?
I have an AS3 function that loads and audio file and then plays it. I have the pre-loader for the first audio file working - now I need to run the pre-load function before the 2nd audio file starts.
myMusic.addEventListener(ProgressEvent.PROGRESS, onLoadProgress2, false,0, true);
myMusic.addEventListener(Event.COMPLETE, playMusicNow, false, 0,true);
myMusic.load(soundFile, myContext); //This code works
[code].....
i'm trying to modify some code and can't figure out what the issue i'm having it. this is the(shortened) code:
public static function Lose():void {
trace("OVER!");
Clock.stop();[code]...
this is the error i get: 1180: Call to a possibly undefined method OverIt.i just want to call a function from inside of the public static funtion.both function are inside this class:
public class Game extends MovieClip {
}
Okay so I am reading through sens tutorial on OOP and updating my game that I am making. It is much easier to code this way (IMO) but still hitting snags.I am trying to get through this code:
[Code]...
I'd like to know what is the difference between MouseEvent.CLICK & MouseEvent.MOUSE_DOWN. Because when i use MouseEvent.MOUSE_DOWN for a button to set full-screen view its doesn't work, instead of this MouseEvent.CLICK works. So what was the reason.
View 3 RepliesI'm making a button for the first time, and I wanted to use a full click to drive it. However, when I use addEventListener(MouseEvent.CLICK, onClickHandler); nothing happens when I click on it. When I use (with the rest of the code being identical) addEventListener(MouseEvent. MOUSE_ down, onClickHandler); it works like a charm.
View 6 RepliesThe main AS timeline creates the enemy instance and calls them via the timer class. Inside the instance enemy movie clip there is some script to do a basic tween and there are functions to remove the enemy and to declare you've hit the enemy. The problem I'm having is when I try to call my KillEnemy function with a MouseEvent.CLICK (or MOUSE_DOWN, MOUSE_UP) event, it isn't registering, I realised this after testing the same function to listen for a MOUSE_OVER, MOUSE_OUT, it worked perfectly.
Can anyone explain why this is happening? Not just that the mouse seems to be a little delicate, even with the roll over listener called it isn't registering the event unless it hits a specific part of the movie clip enemy, which leads me to believe the movieclip is somehow built incorrectly? But even when testing the game with extreme settings (i.e. leaving the enemies on screen for a long time) the mouse clicks aren't registering still. Something is broken! Here is some of code inside the enemy movie clip, the problem lies on line 11:
[Code]...