ActionScript 3.0 :: Event Listeners For MCs On Stage And External Classes?

Nov 6, 2010

I found this code for a contact form at msinghinteractive easy-to-use-flash-as3-contact-us-form-class and it dynamically creates input fields and buttons. I didnt like the dynamically drawn submit and reset buttons, so I added my own MCs(my 'buttons') to the stage. I tried modifying the code and took out the dynamically drawn buttons..However, I cant figure out how to add Event Listeners to the buttons which exist on the stage--Im getting undefined errors...The fla is directly associated to a main.as class which just determines the parameters of the .as class it is tied to -to set the size of the Contact form.This is the entire class:

Code:
package{
import classes.*;
import flash.display.*;

[code]....

where btn is the instance name of my submit button MC.My problem is that because my buttons exist on the stage I dont know how to add Event listeners within that class---or rather doing that doesnt work because the listeners are throwing that undefined property errors--I gave them instance names...

View 7 Replies


Similar Posts:


ActionScript 3.0 :: Add Event Listeners Between Classes?

Mar 11, 2009

So I've gotten into using my own as Classes, and have an interesting question.
My main swf calls a php script that gets data from a mysql database which is returned as XML. Part of that data that is retrieved is a filepath to a jpg image. It then takes that filepath and other information, and passes it to my external class, the "news story" class.

All fine and good. Then, the "news story" class uses a loader to load that image along with some text, organize it, and voila, you've got your own very pretty "news story". (I'm extending the MovieClip class here, though I suppose it doesnt matter)

Now, my main swf uses this component to load multiple of these "news stories". The problem is, theres that load time for the image. The main swf is loading them all one at a time, because they are putting each one together on their own.

The key here is that it be dynamic. So, since we don't know how much text is in each "news story", we also therefore don't know it's height. What I'm doing is creating each story in the main swf, pushing it into a "news story" array, adding an event listener to each ones' loader, and when the event listener is triggered, I want it to go to the 'add content' function where it sets the news story's Y value based off the position and height of the previous story that was added (stacking them, obviously). This makes sense, because otherwise it'd add them all on top of each other and it'd be a jumbled mess.

The problem is, the event listener is on the loader object INSIDE the component actionscript. So, how do I figure out which news story to set the Y value for? Because the eventlistener is listening to the loader, not the class. I hope this makes sense AT ALL. Here is the code:

Quote:

while (fancy shmantzy conditions)
{
/*creates the news story and passes xml data to it (filepath, etc)*/
storyBlock = new StoryBlock(a bunch of parameters);
subCBArray.push(storyBlock); //array that stores each news story info

[Code]....

View 2 Replies

ActionScript 3.0 :: How To Turn Off Event Listeners In Other Classes

Apr 18, 2011

Two buttons, left and right, move the (full screen) backgrounds. If you click the right arrow, the current background moves left, the new background is added to the right, is also moved left, and the old background is faded out. Think of it as a long stream of backgrounds, being moved back and forth with the previously viewed one being faded out with a tween.

The problem is that the arrows appear too soon, and clicking one breaks the whole thing. Main.as adds the arrows & adds the event listeners which then call the functions. The Main.as functions to move the backgrounds use background.moveLeft(); in the backgrounds class, which is where the fade out tweens happen.

So - how do I turn OFF the buttons (added in Main.as) when the tween (in background.as) has finished? I've tried using something like "getNextRoom.addEventListener(TweenEvent.MOTION_FIN ISH, turnOff);" with turnOff referencing the arrows, but it complains that they don't exist (and in the backgrounds class they don't).

View 11 Replies

ActionScript 3.0 :: References To The Main Classes And To Add Event Listeners - Using A Command To Initialize

Oct 11, 2010

Before this application runs, I have to do some basic intialising - load up some stuff, build the display list, check I've got the right xml, wire a few objects together. I'm used to doing all of this stuff in the constructor of Main() - my main application class, but it gets a little unwieldy. Would there be any mileage in offloading this into a command class? Is that common practice? I was thinking that way all that Main() would have to do is just listen for events and manipulate methods of the other main classes. The only thing that concerns me is that Main needs references to the main classes and to add event listeners etc. This could be tricky if it's all set up in a command...

View 1 Replies

ActionScript 3.0 :: Add Event Listeners To MC On Stage?

Nov 6, 2010

I found this code for a contact form at[url]...and it dynamically creates input fields and buttons. I didn't like the dynamically drawn submit and reset buttons, so I added my own MCs(my 'buttons') to the stage.I tried modifying the code and took out the dynamically drawn buttons..However, I cant figure out how to add Event Listeners to the buttons which exist on the stage--Im getting undefined errors...[code]...

View 2 Replies

ActionScript 3.0 :: Set Stage Level Event Listeners?

Apr 7, 2009

As part of a very large project, I want the ability to set stage level event Listeners.
 
This works very easily with MouseEvent s but I can not seem to get it to run properly with KeyboardEvents.  Having google'd this issue I have found very little on the subject.  Mostly noobish type questions of syntax and so forth, but I have seen comment of people claiming to have it work for them.
 
To ensure no issues with any other code, I have made a blank project and blank .as file, with only the event listener code:
 
[Code].... 
 
Click events are always captured and traced correctly, without fail.  Pressing keys appears to do nothing.  If however you mash the keyboards very very quickly, one or two key events will trigger sporadically.  

View 5 Replies

ActionScript 3.0 :: Display What Event Listeners Are Currently On Stage?

Apr 22, 2010

I think I have been generating duplicate Event Listeners behind the scenes which is causing me some problems.
 
I like to find out what Listeners are in existence at a single moment. My code is long so it is hard to go line by line to isolate the issue. It would be faster if I knew what Listeners are were activated.

View 2 Replies

ActionScript 3.0 :: Remove Stage Event Listeners?

Feb 5, 2010

I create a stage keyboard event listener in an externally loaded swf such as:

Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, onDown);

My question is how and where I should remove this event listener? I have added an unload event handler to the external swf like this:

Code:
this.loaderInfo.addEventListener(Event.UNLOAD, unloadHandler);

The unloadHandler code looks like this:

Code:
private function unloadHandler(event:Event):void {
stage.removeEventListener(KeyboardEvent.KEY_DOWN, onDown);
}

When the container swf unloads the external swf, unloadHandler() gets called, but with the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

Where should the keyboard event be removed?

View 9 Replies

Actionscript 3 :: Add Event Listeners To Global Stage Via Class?

May 24, 2011

i am making a simple game i want to be able to add an keyboard event lisnter within the class constructor. However i am having trouble. i undertsand you have to pass the stage through a listed display object property stage? anyway i am getting errors that do not recognise my event listener keyboard event.

package louiseguchi.game
{
import flash.display.Stage;

[Code]....

View 2 Replies

ActionScript 3.0 :: Adding / Removing Stage Event Listeners

Feb 6, 2009

I'm adding and removing stage event listeners I am relatively new to AS 3 and have been building a liquid layout site unfortunately I do not have a strong grasp of classes and have been doing all of my scripting on the main timeline with encapsulated script within MC's.

basically I am calling on the same functions over and over and those are mostly resize functions which I have added StageEventListeners on the appropriate frames to listen for resize events on that stage now as of now I have literally dozens of these scattered about the site. when testing my site things are running fairly smoothly however I keep getting error messages in my output window that go a little something like this.

[Code]...

View 1 Replies

ActionScript 3.0 :: Adding Event Listeners To Stage Buttons?

May 11, 2010

I have 22 buttons (each named buttoni where i is a number between 0-21...e.g. button0, button1, button2) that I've created and artfully arranged on the stage in my .fla file. The document class for the .fla file is People.as, and in People I'd like to give each button a rollover and click event listener, but I can't figure out how to refer to them using a loop.

Here's my code, which obviously doesn't work:

ActionScript Code:
private function initButtons() : void {
for (var i:int = 0; i<numSquares; i++) {
var thisButton : String = "button" + i;

[Code].....

View 6 Replies

ActionScript 3.0 :: Stage Event Listeners Causing Error?

Mar 20, 2012

I have just added a menu screen to my game and I get the following error:

ActionScript Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MyGame()

[code].....

View 4 Replies

ActionScript 3.0 :: External Xml, Textfields, & Event Listeners?

Jul 29, 2010

I am having a problem with putting text from an external xml file into multiple textfields through out the movie. I believe the problem stems from the fact that not all the text fields are loaded. The movie stops intermittently and I want certain xml child to be shown, then later in the movie a different child. I keep on getting the Error #1009 and I am wondering what event listener I should use to solve this. I can trace out the data from the xml but when I put them into textfields not currently on the stage at that particular frame, I get the erro

View 1 Replies

Flash :: Keeping The Number Of Objects And Event-listeners On Stage As Low As Possible

May 23, 2010

I am creating a site with lots of big scrollable text-boxes in it. Each text-box object contained some text, and two buttons to scroll up/down with. The scroll buttons each had an event listener so the text moved when you clicked them.

These text-boxes were stacked on-top of each other with all except one having an alpha of 0. If I wanted to change which text-box is active I move it to the front and call a small TweenLite animation.

To the left (outside of the text-box objects) I have an object similar to a menu. It also has about 12 or so event-listeners (one for every button).

This turns out cause A LOT of lag an it's very troublesome for my laptop to run it. reduce the number of event-listeners on the stage and also the amount of text-boxes.

What I was thinking was to add the text-boxes using AS so I only have 1 on the stage at a time but I couldn't figure out how to do it. I also thought it might be better to just use 1 big event-listeners and from mouseX and mouseY decide which button the user is trying to push.

View 1 Replies

ActionScript 3.0 :: Attaching Mouse Event Listeners To MovieClip On Stage?

Sep 19, 2009

I have a movieClip on stage, inside is a dynamic textfield, and I have set mc.scaleY = 0;
Code:
mc.scaleY = 0;
mc.buttonMode = true;
mc.mouseChildren = false;
And suddenly everything above and below (on the whole stage) where the movieClip actually is receives mouse, I can see by the button mode. But it only happens with dynamic text, not static.
I have attached the example:

View 8 Replies

Actionscript 3.0 :: Event Listeners - Creates A Bunch Of Movieclips And Sets Them On The Stage?

Feb 20, 2009

I have a loop which creates a bunch of movieclips and sets them on the stage.As I create each one I attatch an eventListener to it.My problem is that when the eventListener fires, the function it calls always works on the first mc added to the stage, not the one that fired the listener.How do I fix this?Here's a bit of the code:

Code: Select allfor (var i:int=0;i<numOfItems;i++) {
item = new Item();
//etc etc[code].....

View 1 Replies

AS3 :: Flash - Difference Between Adding Internal And External Event Listeners?

Aug 2, 2011

I have some MovieClip class that has eventListener, added from inside the constructor of the class (it's MouseEvent.MOUSE_DOWN). Now, I want to add the same listener externally, from parent class, for other purposes. Will these two interfere with each other or it's okay?

View 2 Replies

Actionscript 3 :: Android - Attach Mouse Event Listeners To The Stage Or To Individual Sprites?

Aug 16, 2011

In AS3 on Android is it bad from a performance perspective to attach mouse event listeners to individual sprites rather than to the stage? I am writing an app for an Android phone using AS3 in Flash Builder. The app has multiple screens that respond to user touch. The screens are arranged in a hierarchy and show list data so that when you click on an item in a list you are presented with a new screen with a new sub list on it.

I have been using an event listener to detect mouse / touch input and based on something I read that indicated that performance is much better if you keep the number of objects you are listening to to a minimum I have attached the mouse listeners from each screen to the stage object.

This all works fine but I am finding that as I move between screens (and they get popped or pushed onto the dislay stack) I have to keep track of alot of adding and removing listeners to the stage object. If I don't then windows higher up the hierarchy than the current screen keep receiving mouse events.

If I used listeners attached to sprites in each window then when the window was removed from the display even though it is kept in memory (ready to be popped back when a child window is closed) it won't receive any mouse events....

Performance doesn't seem to be impacted using listeners directly on sprites when using my HTC phone to test with, however I obviously don't know what it will be like on other phones. Does anyone have any experience either way or a view on the best approach?

View 1 Replies

ActionScript 3.0 :: Static Function That Remove The Object From The Stage As Well As Removing Its Event Listeners?

Oct 12, 2011

I want to make a static function that I can use in all the custom classes.It should be some kill(); function that would remove the object from the stage as well as removing its event listeners. I made it in Document class, and it didn't work. Here's the code:

ActionScript Code:
public static function kill(e:DisplayObject)
{[code].....

View 3 Replies

ActionScript 3.0 :: Flash Event.target.name In External Classes?

Aug 3, 2011

How do I call this function for multiple listeners without IDE timeline and frame names, using external classes? Im moving my timeline code to classes, and Im stuck with this..

View 4 Replies

ActionScript 3.0 :: Access Elements On The Stage From External Classes?

Nov 19, 2009

[code]Also pass the Stage reference still it not showing any error and text box is also blank,text is embed ed and the code is.[code]If I put import flash. display. List; it shows an error 1172: Definition flash.display:List could not be found.

View 5 Replies

ActionScript 3.0 :: Button Setup On Stage - External Classes

Mar 31, 2010

This is my first attempt at external as classes and I can't get them right. I've a button set up on the stage and an external as file with the following code:

Code:
package {
import flash.display.*;
import flash.events.MouseEvent.*;
import flash.display.SimpleButton.*;
public class myTasteButton extends SimpleButton {
[Code] .....

Basically I need to link an external class to the button, which will in turn when clicked play the beat_mc. I've given the button the class of myTasteButton. It's not working but I'm not getting any errors.

View 4 Replies

ActionScript 3.0 :: Working With The Main Stage Inside Of External Classes?

May 6, 2010

I'm working on a lot of different flash applications Most of those applications are visual and involves the main stage.I started oop a while ago and i got to a point that %99.9 percent of my code is extracted to different classes.There is one thing that repeat on a regular basis on all of my apps, passing the Stage variable to the different classes....It's working great but it doesnt feel right that i need to pass the main stage as a variable between the different classes,is there a better way to access the stage from external classes ? can i make the main stage a static property and access itwithin all the objects in the application ?

View 1 Replies

Actionscript 3 :: Removing Event Listeners Not Working - Error #2094: Event Dispatch Recursion Overflow

Nov 24, 2011

I have this in my constructor:

[Code]..

The problem is I get Error: Error #2094: Event dispatch recursion overflow. Why does removechild keep getting called if this.parent does not exist? Why doesn't removing event listeners work?

View 1 Replies

ActionScript 3.0 :: Can Event Listeners Only Be Added To The Class Which Dispatched The Event

Sep 3, 2009

Can event listeners only be added to the class which dispatched the event? I ask because I want to have the logic for the listener on the main class, and the action is dispatched on click from a thumb which is instantiated in a scroller class. Kinda like this:

ActionScript Code:
pseudo code:
class main {
main() {

[code]....

This doesn't work. Why can't the main class listen for an event on the thumb class?

View 1 Replies

ActionScript 3.0 :: Event Listeners Only Fire Off At Event Once?

Feb 13, 2010

An odd thing is happening for me, my eventlisteners only fire off once then they seem to stop working.

This thing is a movieclip that slides up the parent movieclip and another movieclip within mc slides it down. They only work once.

ActionScript Code:
slider.up.addEventListener(MouseEvent.MOUSE_UP, activateSlider);
slider.down.addEventListener(MouseEvent.MOUSE_DOWN, activateSlider2);
var frameBoolean:Boolean = false;

[Code].....

View 9 Replies

CS3 Calling Functions Using Event Listeners?

Aug 7, 2009

I have made an event listener:text0_mc.addEventListener(MouseEvent.CLICK, showMe);showMe is a function, but I need it to call more than 1 function at once i.e. -ext0_mc.addEventListener(MouseEvent.CLICK, showMe1, showMe2, showMe3, showMe4, showMe5, showMe6, showMe7);Each function contains an if statment as below.

function showMe1(event:MouseEvent):void
{
if (shuffledArray[1]==orderArray[1]){

[code].....

View 1 Replies

ActionScript 3.0 :: Using Multiple Event Listeners?

Sep 27, 2009

In AS2 you could add an onRelease to multiple buttons like this:

Code:
onebutton.onRelease = anotherbutton.onRelease = lastbutton.onRelease = function() {
//do something when either button is pressed;
}

Is there something similar possible in AS3 using addeventlistener? Besided copying the same addeventlistner line for all individual buttons?

View 1 Replies

ActionScript 3.0 :: References And Event Listeners?

May 17, 2010

Lately I've been twitching in the back of my head wondering just how many references to objects that I'm making, and whether or not they are getting GC'd or not.My question in this sense refers to event listeners and whether or not they are removed in certain cases where you get rid of an object. Two examples:

First, and I think this one is an easy one... when you create an object that adds an event listener to itself INSIDE it's own methods (e.g. this.addEventListener(e:Event, function)), when you REMOVE that object (this), do it's event listeners disappear too? I can only say yes, because they are referencing THAT object and are INSIDE that object.

So I think that question answers itself (but I'd love to know if the truth says otherwise).

But secondly, if you add an event listener to an object from a sibling or parent object, and then remove the object, does that event listener stick around, therefore maintaining a reference to that object and keeping it in memory? And is that the concept that people keep referring to of 'weak' event listeners? E.g. someChildObject.addEventListener(e:Event, function)Also, are event listeners by default strong or weak?

And I am assuming that 'yes', it DOES keep the reference. Which, if you are a n00b programmer like me, you probably are all like, 'aww sh*t damn, how am I supposed to make sure that my objects are getting thrown in the garbage collector's mouth of goodness every once in a while?

View 1 Replies

ActionScript 3.0 :: Using Multiple Event Listeners

Jul 1, 2009

I have a movielcip (A) class in which I have used a Tween class effect on a child movieclip (B) scrollRect. The (B) Movieclip in turn has several movieclips whose have tween class effect being executed on thier child movieclips.the tweens are all unique to each movieclip and the event listeners are taken off once completed.This works all well and good in FLASH IDE..My problem arises when I try to view this in a browser on a Windows XP.[code]

What is happening in most cases it that the animation appears to "stick" but i think what may be happening is the listening or removal of the event listeners. The animations are left incompleted.Is there any rule of thumb when using multiple event listeners?[code]the effect disables and re-enables the buttons when its done.... then the listeners are removed.each one with the exception cretes its own unique tween (obviously this is a custom class built as each clip)

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved