ActionScript 2.0 :: Access The Parent Of A Listener From A Listener Object?
Feb 11, 2008
I 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.
TypeError: Error #2007: Parameter listener must be non-null.at flash.events::EventDispatcher/removeEventListener() at project1_fla::MainTimeline/btnName()
Basically I don't want the MOUSE_OUT and MOUSE_OVER functions of the parent being triggered whenever I mouse over the childMC inside of it. Is there any way to prevent this?
This isn't an exact duplicate of AS3: add event listener to loaded swf, actually it seems to be a mirror situation with non-mirror solution..
I have a test flash file that registers its own listener at first frame's actions.
trace("it's going to be OK"); stage.addEventListener(KeyboardEvent.KEY_DOWN, aKey);
Unfortunately neither line works when .swf is loaded into another movie. Assuming that stage object is wrong for such situations, which object should be used to get listener?
Is it necessary to rewrite loader in parent swf, as said in the linked question?
I am trying to create a project where I have a homemade button with a label component inside converted to a MovieClip. I have added an event listener, which triggers successfully when I move into the MovieClip, but retriggers when I move into the label within the MovieClip. Is there anyway to tell it to stop retriggering and act as a single MovieClip, or would it be simpler to break down and just try to customize the Button component?
As a child of Main, I have an instance of a class called NavMenu.
As children of NavMenu, I have multiple instances of a NavLink class: navLink01, navLink02, navLink03, etc.
Back up in the Main class, there is a function called navigateTo, which accepts sectionID variable as an argument.
My question is, what is the best practice to get the navLinks to call the navigateTo function on Main? I've been told that in the spirit of encapsulation, it is not best to pass a reference to Main down to the navLinks, and call the function from there.
But rather, it is desirable to use the event listener/dispatcher method, where the navLinks are dispatchers, while the Main class listens for the navLinks to broadcast their sectionIDs.
While this makes sense, however, don't you still have to pass a reference of the listener on the Main class down through the hierarchy, so that the navLinks are registered as dispatchers? Doesn't that defeat the purpose of encapsulation?
I have created event listeners for a particular movieclip.Insidet this movieclip there is so many objects.When ever I click on the parent movieclip the event listener calls the function for the child object. I had tried removeEventLIstener()
import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; var info:MovieClip=new MovieClip(); info.graphics.beginFill(0x000000,0.35); [Code] ..... I want to delete mc's parent
I want to a listener on a tween on the document class that when it's finished, it goes to it's child's listener function, but I don't know how. I thought it'd just be a case of document.functionName but it's throwing an error.
[Code]...
1061: Call to a possibly undefined method startFade through a reference with static type Class.
I'm having a real difficulty in action script 3 using my xml data from an external source. I have no difficulties importing or manipulating the xml data, the difficulty lies in accessing the information in a different function.
Alright, 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.
I'm using the following addlistener to listen for a custom event the event works if i put e.Event in the functions parameter but i don't get the passed variables however if i go into the .as folder where the dispatch originates and put EventType in the parmeters field of the function then i get all the variables.........but if i put EventType instead of e.Event in the first example then I get undefined for EventType.....how do give access to EventType?
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).
trying to find how to assign listener to an object created with this function...
Code: private function placeBtn(thumb:String, Xthumb:Number, Ythumb:Number, targetHolder:MovieClip, ID:String):void{ var clipHolder:MovieClip = new MovieClip();
I'm having trouble with buttons. I've tried two sets of code and get the same result: an "1120: Access of undefined property enter_btn" error. Here are the two sets of code I am using:
Code: function onEnterClick(evt:MouseEvent):void { gotoAndPlay(71); }
[code]....
I've set the instance name for the button but keep getting the error. Do I need to set up a variable first?
I have four buttons named button1, button2, button3 and button4. I want the code to trace the name of the button when the button is clicked. This is just an eample of what I'm doing in my project. The project itself is too convoluted to put up and explain. My problem that needs to be solved is, how do I refer to the button in the Function?
var c:int; var buttonName:String; for (c = 1;c < 5;c++) { buttonNum = "button"+c;
[Code]....
When I say "trace(this)", the code doesn't know what "this" is because I've taken this[buttonNum] out of the loop by having to put it in a Function. How do I call to the object that is in the listener that called the Function?
ActionScript Code: /* Setup listener for each video/audio cue point ============ */ myListenerObject.cuePoint = function(evt:Object):Void { if ((evt.info.time == cpTime[n]) || (evt.time == cpTime[n])) {
[Code]....
The code above does not work because of the if/else if statements. What I'm trying to accomplish is that I have a listener object that in one frame listens to an flv playback object, and in another frame listens to an mp3 file.
The listener code for both types are exactly the same, except that the flv listener uses the evt.info.time to check for cue points in the flv and the mp3 uses evt.time to listen for the cue points in the audio. Since I can't combine these with an OR operator, is there any other way to consolidate these two, or do I just need to keep two sets of the same listener code for each to refer to?
I have these buttons in a movie clip and I would like to have only one event listener for the parent, using event.target to point to the children. I have also tried event.currentTarget, and it didn't work.here is the code that works:
I 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?
$("#listView object.modal").click(function(){ // Get the ID of the clicked link: var link = $(this).closest("h2").attr("title");
[Code]....
This fires a modal (jQuery UI). It it working in FF, Chrome/Safari but not in IE 7/8. Is there something I'm missing here?
Big Picture: We're using a swf to render custom type and there is a link in the rendered (flash) content. We're hoping to catch the link action in the jQuery listener so we don't have to extend our swf have an optional param to return false on link click.
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:
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:
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?
I have two scenes in flash - when you go to scene 2 there is a eventListener attached to the stage to move a movieclip. When I test the movie the only way the keyboard listener seems to work is if I click on the stage first, then the object will move. Is there a solution to this. The code I am using is:
is 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.
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?
This is something that tugs at my mind a lot so I figured I'd ask the community. If I have a class called MyParentWidget and it contains an instance of MyChildWidget with an instance name of myChildWidget then I will often do something like this: