I've been thinking about how the garbage collection work for a while now and have to ask if its necessary to removeEventListeners before you null a class like this:
ActionScript Code: var _nc:NetConnection; function init():void {
[Code]....
Obviously I can skip the removeEventListener but will it affect the memory usage if I don't remove it?
I am creating a small image gallery and I am creating the actual images dynamically. The images are stored via json and I am listing them underneath each other. No I can get all to work and they all load and position each other correctly underneath. What I would like to do is assign each image a addEventListener so that when clicked they pass the necessary details onto another function which will then display a larger image simple and basic but I am having trouble with adding the eventlistener. each one gets an eventlistener to it but when clicking on each one they all show the details from the last one. The code is attached to the main gallery container is as follows:
I want to know if there's a 'correct method' in removing a MovieClip off the stage. I am currently programming in simple OOP and I have 2 classes, for now lets relate them to Tree and Fruit. The fruit is the child of the tree.
When the fruit is being clicked on. the tree AND the fruit will fade off and I will perform a removechild only on the tree. So I'm now puzzled if just removing the tree would automatically remove everything including the fruit(without performing a proper tree.removeChild(fruit)) and all the eventlisteners attached to fruit?
If not, must I perform remove child on every single MC/Sprite I have added onto tree/fruit for the best performance? Would like to find out how you go about doing it the 'correct way'.
I have an actionscript project which uses visual symbols from an SWC. I have a CheckoutButton which has the following class associated with it (compiled into the SWC in Flash CS3).
I'm working on a game where users can win buttons/badges as awards. I estimate there will be around 500 awards, in all.I want to allow the users to sell their duplicate/unwanted badges to the bank and buy new ones from the bank.I am showing the badges in multiple awards frames. Below the badges, I show the count, along with a "Buy" and "Sell" button.My question is: What's the best way to handle SO MANY buy & sell buttons? Is there a way around coding 1000 eventListeners and 1000 eventHandlers?
One possible solution is to name my buttons, incrementally, like "buy_mc1", "buy_mc2", etc. Then do a loop to create listeners for this["buy_mc" + i]. However, I would then have to make VERY sure that I link these back correctly to the awards.Currently, I have an "award_mc" field in my database, which stores the name of the movieclip in my .fla. From that, I can access related assets, like the count field, like: this[db.award_mc + "_count"].txt.Unfortunately, this method does not lend itself well to looped access.Maybe I can create an array of movieclip names that are in synch with the buy/sell buttons. For example:
When someone clicks a button, I can link buy_2 to "ubernessAward", then look for "ubernessAward" on the database.How can I get the number from the button, though? Even if I can loop through setting up the eventListeners, will I have to set up individuatl eventHandlers to process the correct index number? I was not able to get this to work with buttons on the stage. Apparently, buttons are a static class. MovieClips are dynamic, so I was able to get this to work by using MovieClips. Here's what I did:
Added 3 MovieClips to the stage. Named them "mc0", "mc1", and "mc2".
From here, I can tie the awardKey to an array of MovieClip names. Then, I can use the MovieClip names to read my database.This is why I come to Stack Overflow, FIRST, when I have a problem. :)
I am trying to learn working with multiple classes in AS3. I came across a problem which I can not solve or look up. I have searched the documentation but I can not find a clear sollution or answer.I have flashfile with a document class (main class). Within this class I use another class (circle class) to get a instance of a movieclip on the stage.
Now my problem is that I can not place the eventlisteners to the circle class. normally I would write something like this. addEventListener() but this doesnt work. But I really need a way to get this to work, because I want to make a mouse click event which must be linked to the circle to respond to it.
Currently one of our teams suffers from a very strange phenomena: after manipulating the z property of a MovieClip and changing the stage quality some event listeners of nested MovieClips seem to disappear (or at least not react to the proper events any longer).
The problem also only appears when doing both, changing the stage quality and manipulating the zproperty.
I've created a grid of 3D cubes using modulus, and the 3d cubes are were created from the Math and Flash Tutorial, if you are interested it is here.What I am trying to accomplish (and it works, just the performance is lousy). All the cubes in the grid are inactive until the mouse hovers over them, then they start to rotate, and once the mouse moves off them they continue to rotate...
So to create the grid of cubes:
Code: public function FlowerMenu(){ var rowY:Number = 0; for (var i:int = 0; i < 190; i++) {
[code]....
So, this works, but after about 4 or 5 cubes have started rotating the performance drops considerably. I can imagine creating that many EventListeners isn't a good idea, but I can't see any other way of doing it.
I have to use many custom classes for a project, each class includes lots of elements(methods,properties) and I generally forget their names when coding. Is there any editor which I can enumarate the elements of my classes after pressing "." like Flash's built in classes?
Let's say I have a global SoundChannel object, and inside a function I am repeatedly creating new instances of the Sound object to play songs one after the other. Each time I do this, I need to add a new eventListener to the SoundChannel to call the function 'onSoundComplete' that will load the next song on completion.Coming from a strict C++ programming background, I often wonder if it's necessary to do some kind of cleanup in Flash, or if it handles it automagically.Here's example code that specifically removes the eventListener from the previous Sound object everytime a new one is created, but I don't want to be doing this if it isn't necessary:
Code: // Setup sound object buffer var slc:SoundLoaderContext = new SoundLoaderContext(3000);
I have images loading from an array. A slideshow. This works fine, but they pile on top of each other. I cannot figure out how to remove them. what's the simplest way to remove them? How do I say - if pic1 is loaded, before loading pic2, remove pic1?
Code:
var aPics:Array=new Array("pic1.jpg","pic2.jpg","pic3.jpg","pic4.jpg","pic5.jpg"); var threeSeconds:Timer=new Timer(3000,aPics.length); threeSeconds.start();
Trying to add EventListeners to Bitmaps.Can I add an EventListener directly to a bitmap?If I load an image to a UILoader then addEventListener to the UILoader instance that works just fine, but if I use a Bitmap instead, nada...I could load the Bitmap into a Sprite and add the EventListener to that, but would prefer the direct method...
The examples I'll use don't do anything - they're classes without ANY members - no variables, methods, anything.
Let's say I extends Sprite and call it MySprite.
I save it in test.core
[code]...
Now I create another custom class called MyWindow that extends MySprite.
I save it in test.windows
[code]...
Then I create another class that extends MyWindows (the example I'll use is a document class - but that doesn't matter - I've tested using an instance too).
[code]...
Notice that I'm not even trying to instantiate the helper classes - just having them there throws the error.
If there is only a single helper class, everything runs fine.
Also note that - as far as I can tell - this only happens when extending one class from another package, then extending that class with more than one helper object.I'm pretty sure there's no namespace bumps or typographical errors, as this is a very pared-down version of the original application.
EDIT: seems the problem exists even without the crossing packages - even extending MySprite in the document class with multiple internal classes generates this error.
I am creating a library in AS3. Inside the library I make use of a bunch of classes/packages that need not be exposed to the end user of my lib. I want to only expose one of these classes.
I guess my questions are:
1) How are libraries commonly distributed in AS3?
2) Is there a .jar equivalent in AS3 that developers can include, but will only have access/knowledge of the classes I've declared as public?
Is there a way to listen for the cursor in the input text field? I am making a form, and when the user clicks on the input box I want text to appear to the right side and than fade when they leave that text field.
the text field is called input_txt;
psuedo code
input_txt.addEventLister(event.MouseEvent, showText); function showText(evt:MouseEvent):void{ text_mc.visibile = true; }
I'm working on an image gallery which builds dynamically at runtime, simple enough.imageList is an array loaded with the images to display.
var imageList:Array = _root.images.split(",");var imageArray = new Array();var count = 0;for( var i = 0; i < imageList.length; i++ ){ _root.createEmptyMovieClip("myMC"+i, (i + 1)); _root["tmpMCL"+i] = new MovieClipLoader(); imageArray[i] = new Array(); ima
Inside a .fla file I have some buttons and each button will tween a different image to the stage. All the images are outside the stage in the same x and y position and I just need to tween the x coordinate.
Now I'm working with an external document class where I'm trying to hold all my functions and I'm stucked with the Tweens. I'm willing to stay away from the flash tween engine and I'm trying to work with tweenLite.
Is it possible to pass parameters through eventListeners so I can use something like this inside my docClass?
public function animeThis (e:MouseEvent, mc:MovieClip, ep:int):void { //ep stands for endPoint. TweenLite.to(mc, 2, {x:ep}); }
If this is possible, how am I supposed to write the listeners so it will pass the event to be listened for AND those parameters? And how to build the function so it will receive those parameters and the event?
I've got a few MouseEvent listeners outside of a function that contains nested functions that need to use the functions attached to the listeners.
button1.addEventListener(MouseEvent.ROLL_OVER, buttonOver); function navigation (): void { if statements;
[code]....
I keep getting an "1120:Access of undefined property buttonOver" error. I know it's because the EventListener is outside of the function "navigation" but I need it to be accessed by other functions later.
I have main.swf and content.swf. I load content into main. When I try to unload it gives me error, due to the fact that in my content.swf I have MouseMove event and this event is causing this error:
ActionScript Code: TypeError: Error #1009: Cannot access a property or method of a null object reference. at content_fla::MainTimeline/onLoop()
How to properly kill all eventListeners?
My main.swf code:
ActionScript Code: var holder:Sprite = new Sprite(); addChild(holder);
[Code].....
I did some research and it seems quite an issue - especially when trying to remove, enterFrame, mouseMove or stage listeners. Im using CS3.
I tried using a .enabled = false; when I already had a click event on that movie clip. I found that you need to remove the eventlistener instead of making enabled false.Why doesn't enabled work when you have event listeners?I'm really more curious than in need of an answer since removeEventListener worked fine.
I have a menu with buttons on the stage that when clicked load external swf but the problem, although i can remove them from the stage, is that they are still playing which gives my site performance problems. I gave weak references to the Event Listeners but i didn�t remove them.Here�s the code:
Code:stage.addEventListener(KeyboardEvent.KEY_UP, reloader); function reloader(e:KeyboardEvent):void {[code].....
and this:
Code: var reloadT:Timer = new Timer(2000, 2); reloadT.addEventListener(TimerEvent.TIMER, on_timer); reloadT.start();[code].........
So I have a code that tracks Key_UP and one for a timer. However, I want to somehow use them together, like inside each other: ex. Run the timer function in Key_UP.I want to trigger the timer only if Key_UP is found. How would I do this?
Right now I'd also like to call that same function using the ENTER from a keyboard since loginOnClick doesn't use the parameter received (event:MouseEvent). So I did this:
Code: function keyboardListener(event:KeyboardEvent):void{ if (loginButton){ if (event.keyCode == Keyboard.ENTER && loginButton.enabled) { loginOnClick(); // Generates an error because it doesn't have a parameter. } } usernameTextField.addEventListener(KeyboardEvent.KEY_DOWN,keyboardListener);
Problem is, of course, AS3 doesn't let you call a function with the incorrect number of parameters or types. I tried following senocula's tutorials on functions and parameters but they don't seem to work on this very specific issue considering the parameter is an event reference.
i need to attach an event listener, and have its handler have a variable passed into it ..this possible?
Code: mc.addEventListener(Mouse.Event.ROLL_OVER, over(obj) ); function(e:MouseEvent,obj:Object):void{ e.removeEventListener(....); trace(obj); } .. sommint like that .. as3 says function is static, missing argument etc .. there may be other ways about it - but it is crucial to my setup, as when the EL is added, the object passed is only obtainable at that point.