ActionScript 3.0 :: Run Event Listener Through Dynamic Object Call
Apr 27, 2009run event listener through dynamic object call
View 1 Repliesrun event listener through dynamic object call
View 1 RepliesI have a movie clip being dynamically added to the stage via an AS3 linkage call:
gameOver_mc = new GameOver();
stage.addChild(gameOver_mc);
The movie loads as required.But when the movie has been added I want the user to be able to press spacebar and a function to run.So in the GameOver.as class I wrote the following:
Code:
package
{
import flash.ui.Keyboard;
[code]...
But as soon as the movie clip tries to load I get the error message: TypeError: Error #1009: Cannot access a property or method of a null object reference.I would have thought this would work fine. When I trace the statement in the Constructor function is works. Its only when I try to add an event listener that I get the problems. So am I not allowed to add event listeners from a dynamically loaded class?
isit possible to call two functions from one button event listener?
or is it even possible to write two seperate listeners for one button that listen for the same thing an example is shown in the code;
also, i have string variable, that i want to use to call a certain funtion depending on the variable, for example the vairables name is phase_no can i do next_btn.addEventListener(MouseEvent.CLICK,nextPhase,beginSubmit+phas e_no)??
How do I call the slideShow function without an event listener?[code]...
View 1 RepliesSo I have an event listener, and I call a function from it.. but I want to pass some variables along with it as well.Is that possible?
View 10 RepliesSay I have the following function
Code:
function myVideoFunction(event:VideoEvent):void {
do some stuff....
}
but i want to call it from the event listener
Code: button.addEventListener(MouseEvent.CLICK,myVideoFunction);
I cant because it runs off a VideoEvent, not a MouseEvent.The obvious work around is to copy and paste the function and rename this part, or alternativly just make a function such as:
Code:
button.addEventListener(MouseEvent.CLICK,callMyVideoFunction);
function callMyVideoFunction (event:MouseEvent) {
myVideoFunction(null);[code].....
The keyBoard event listeners call on the rotate and unrotate functions and based on the key inputs(A and D) will implement either of the functions and rotate the image or return it to the original upright position. However, I haven't been able to get the function to work. When I press the A or D keys on the keyboard nothing happens. I even put trace() in one of the functions to see if the function will even be implemented but I don't get anything. I put in my Scripts below. Why are the functions not working? Do the eventlisteners fire or are there conflicts? I'm not getting any error messages.
ti.border = true
ti.addEventListener(TextEvent.TEXT_INPUT, onInput);
function onInput(event:TextEvent):void {
if(ti.text.search('a')!=-1) load_image("http://i54.tinypic.com/anom5d.png", "ottefct");
[code]....
The keyBoard event listeners call on the rotate and unrotate functions and based on the key inputs(A and D) will implement either of the functions and rotate the image or return it to the original upright position. However, I haven't been able to get the function to work. When I press the A or D keys on the keyboard nothing happens. I even put trace() in one of the functions to see if the function will even be implemented but I don't get anything. I put in my Scripts below. Why are the functions not working? Do the eventlisteners fire or are there conflicts?[code]...
View 1 RepliesHere is the code to call function using event listener:
var listListener:Object = new Object();
istListener.change = function() { changeImage(); }
thelist.addEventListener("change", listListener);
[code]......
I've been lookign around for this but cant seem to find how to do it. How do you make a array of buttons then call it in a event listener? The idea is that I don't have to creat code for each button. it can just run it over for each button.
View 3 RepliesAlright, I've looked online at a bunch of different collision tutorials but they don't explain what I'm looking for. I want object A to hit object B and then execute a function via to a Event listener.
View 1 RepliesI am loading 5 images using "for loop" and I have created the listener and if the images completes the loading, the function is called. Now, I need is the name of the "image" which is loaded on each five images gets completed.
[Code]...
in the output it is throwing as "[object LoaderInfo]". Now i need is the name of the "Image", inside the thumbnail_load function, that means, which image loading is completed.
stage.addEventListener( MouseEvent.MOUSE_DOWN, clicSouris);
function clicSouris( pEvt:MouseEvent ):void { var positionX:Number=pEvt.stageX; var positionY:Number=pEvt.stageY;
[Code]....
what appens when I add an Event Listener to Object Event?
Following the logic with the display list in AS3, I thought only Classes who inherit flash.display.InteractiveObject could react from events coming from mouses (or keyboard).
I'm new to ActionScript and am having trouble hooking up callbacks to take extra, dynamic args.The basics are: I have a method that takes a couple of parameters, uses a RemoteObject to send an operation to get a third value, and I want to pass all three (the operation result and the original two) to another callback.[code]This does allow passing extra args, but it is adding a new listener each time createMeeting is run. So I would need to remove the old listener, but I don't have a handle on the old callback since it was dynamically created/anonymous (I'm not sure of the correct AS terms).I guess I could create a custom event dispatcher that kept track of the previous listener. But maybe removing and adding new listeners each time is the wrong solution to begin with. How would you set up a listener like this when the extra parameters you want to pass to the callback will be changing?
View 9 RepliesAdding addEventListener too a Child object
I am programming a "build a tower" game. After removing the event listener from the first movieclip, flash won't add the event listener to the by as3 to the stage attached new movieclip.
Error MSG:
TypeError: Error #1010: A term is undefined and has no properties.
at stackers02_fla::MainTimeline/keyDownHandler()
Code:
//Vars
var $newObjectName:String;
var $direction:String;
var $level:int;
[Code].....
I'm trying to add an event listener inside an object but it doesn't seem to work. other OO languages it makes sense for an object to be able to attach events etc itself rather than have some external action do it.Here's an example of what I'm trying to do:
ActionScript Code:
package {
import flash.display.MovieClip;
public class Player extends MovieClip {
[CODE]....
This gives an error "1120: Access of undefined property MouseEvent." suggesting that I don't have access to MouseEvent from within the instansiated object.What I can do is create an instance of the class from the Document Class for example and then do the following:
ActionScript Code:
newInstance.addEventListener(MouseEvent.CLICK, newInstance.mouseClick);
I'm pretty new to AS3, but I have not managed to solve the following problem: basically adding instances of a bitmap on the stage (working), but then adding an event listener and knowing which is which. So for the first part:
[Code]....
I have to develop an application in flex. In that application an user can draw line while dragging the mouse. Then if he clicks on that line it should be selected. How to add mouse click event listener to a line object?
View 3 Repliesis it possible to determining what object calls a function based on an event listener? for example, i have 2 buttons on stage that call the same function when they are clicked. i'd like the function to determine which button was the sender.
[Code]...
Ok I have this 100% width/height Flash embedded and when the user moves the mouse I want to display a panel, which disappears after x seconds if there is no more mouse movement.
I think I need an addEventListener, but I am not sure MOUSE_MOVE is the correct one. When the mouse stops moving I need to start x seconds to hide the panel, so I think with a timer?
[Code]...
I have a document class called Main.as In the class constructor I have the following listener:
enter code here
var listeningFORModeChangeToStudent:Sprite = new Sprite;
listeningFORModeChangeToStudent.addEventListener(TellAllModeChangeToStudent.STUDENT,exp);
addChild(listeningFORModeChangeToStudent);
[code]....
In a third class I make a call to the despatcher in the previous class:
enter code here
var ThisTellAllModeChangeToStudent:TellAllModeChangeToStudent = new TellAllModeChangeToStudent;
ThisTellAllModeChangeToStudent.tellAllModeChangeToStudent();
I have trace statements in eveything and from this I know the despatcher in TellAllModeChangeToStudent is being called.The problem is that the listener in the main.as is not calling the function exp.I cant see why and I dont know how to check if the listener is actually seeing the dispatch event?
When you click on the button something happens. However it seems redundant to me that in the declaration of myListenerFunction, the event object e of class MouseEvent, actually has to have its data type MouseEvent mentioned.
[Code]...
this is the error I am having:
TypeError: Error #2007: Parameter listener must be non-null.at flash.events::EventDispatcher/removeEventListener()
at project1_fla::MainTimeline/btnName()
here is my code:
ActionScript Code:
import caurina.transitions.Tweener;
import caurina.transitions.properties.ColorShortcuts;[code]..........
I hava a button on the stage as instance name button.Inside the button objectd,IN the second layer of my button, I added a dynamic test with instance name dynamictest.When I add code to my first frame in the main stage time line, the program can not identfiy the dynamic text with instance name dynamictext.Should I say button.dynamictext.
View 4 Repliesi have some actionscript that makes a
ExternalInterface.call('someFunction');
call.is it possible to reference the html object that made the call to someFunction directly using the ExternalInterface.call call?
Assume that the object that makes the call also has some Callbacks (via ExternalInterface.addCallback) that are accessible via javascript.
Currently:
Actionscript source
ExternalInterface.call("someFunction");
ExternalInterface.addCallback("someCallback",someASfunction);
[code]....
I am making a Scrollbar component and I want a script to call a calculation function for resizing the scrollbar when a new data is loaded.I was experimenting with Object.watch but it's use is beyond me. I don't understand if its the thing I need.Can Object.watch call a function when say a dynamic textfield's data is changed?
View 13 RepliesI am having a weird problem with scope/reference. I am using a loop to preload a number of thumbs in one go, I am creating a different listener for each one on the fly and then passing event handlers for each one of them. This should not be difficult using a loop, but somehow I cannot access the the parent object on my listener and therefore I can't do much with my thumbs after they are loaded.Here is the relevant segment of my code. myThumb_mc is a temporary variable that does not exist when the loop finishes, you can copy and paste this code to test it though. It should work to that extent. (you'll need an image1.jpg to be in the same directory)
Code:
var myThumb_mc = _root.createEmptyMovieClip("myThumb_mc", _root.getNextHighestDepth());
myThumb_mc.clipLoader = new MovieClipLoader();
myThumb_mc.clipLoader.loadClip("image1.jpg",myThumb_mc);[code].....
The code above works, but it does not look nice and it cannot be the right way of doing this. Long question short, how can I access the parent of a listener from a listener object? ._parent does not work.
I am trying to learn JavaScript and I am wondering whether JavaScript has a event listener just like ActionScript's ENTER_FRAME. Basically, I want this event listener to listen "all the time" not just wait for any particular instance (mouse click, keyboard event) of event.
View 3 Repliesif I have an event listerner (mouse, keyboard, enterframe,....event) that is being triggered, and when it finishes its event, something that is able to detect the finished event listener and fire out another sets of event.
It works more like MOTION_FINISH in TweenEvent, but it is only available for TweenEvent only, what if I want to detect a mousclick, keyboard, enterframe or even touch event?
My stage has about 25 buttons on it. Each button when pressed to tweens the background to some random x/y coordinates and then loads an external swf file.This is all working, but the timing is off. How can I wait for the initial background tween to end before I make the loader call to the .swf file.Currently each button's behavior is called on the MouseEvent.CLICK event which calls a function that knows its unique filename.swf. I know you can add the MOTION_FINISH even to the tween event but then I would have to call a new function and lose track of the button that initially called it.
View 3 Replies