ActionScript 3.0 :: ENTER_FRAME On Objects Vs LOOP Performance?
Jun 8, 2010
So for my current project I am to handle A LOT of objects on the screen. Which made me wonder what approach I would go about the ENTER_FRAME event.I have 2 samples below, one where my BulletControl object calls on every bullet object's 'FrameFunc()' in its own ENTER_FRAME event with a for loop.The other sample every object has its very own ENTER_FRAME, so it works independently.
[code]....
Also for each burst of bullets I create about 50 objects or so; a lot of object instantiation is never good with such a short interval which makes me wonder if the garbage collector has a hard time keeping up.
I'm devloping some library classes for flocking/steering behaviours on large numbers of objects (2000+). I'm finding that at < 500 instances, performance is reasonable. As the numbers increase, framerate bogs down.
I've seen remarkable performance with libraries such as Flint or Box2D with ridiculous #'s of particles / objects, so it should be possible to optimize / refactor my code to be a bit better.
I'm aware of the basic optimizations, such as bitwise operations and optimized for loops. Are there any more fundamental approaches I should be considering? For example, currently each instance is a vector-based MovieClip. Would working with BitmapData be more efficient?
I have an application with about 20 models and controllers and am not using any particular framework. What is the best practice for using multiple remote objects in Flex performance-wise?
1) Method 1 - One per Component - Each component instantiates a RemoteObject for itself 2) Method 2 - Multiple in Application Root - Each controller is handled by a RemoteObject in the root 3) Method 3 - One in Application Root - Combine all controllers into one class and handle them with one RemoteObject
I'm guessing 3 will have the best performance but will be too messy to maintain and 1 would be the cleanest but would take a performance hit.
I have 500 small objects, I would like for them each to rotate (spin) constantly, I have seen a few methods for doing this, but what would be the best way to do this so performance doesn't slow down?
I was wondering if addChildAt is slower than addChild, and if so, how bad it is. I want to add objects at runtime, constantly, but they must be behind the player, so I'd use addChildAt to index 0, I figured. However, would this damage my performance? It's for my scrolling platform engine, I want buildings in the 'background' only on the display list when they actually can be seen (code for this is working fine, runs at about 160 FPS last time I checked).
So, should I look into another solution? The only other solution I know of is to have a second 'layer' sprite in the engine, but since it's scrolling, I'd have to scroll 2 sprites all the time. Don't know the best thing to do here
i am using soundmanager to order sounds. my site preview, in home page, square shapes comes into stage and you can drag drop them, all shapes binded its own sound. if they are colliding binded song will play.
the problem is i have 3 second timer to control sounds. every timeout i have to stop sound and play again for synchronous issue, that is my solution for that part. but sometimes before loop, there is an annoying little silence.
Will I take a big hit in performance using nested ViewStacks? Should I strive to handle all navigation in one ViewStack and push children manually or will the affected performance be negligible?
We have a medium size Flex 3.6 application that contains around 20 different page views (managed via a single lazy ViewStack) each having multiple components. Most use custom renderers.All model data is loaded at startup and changes to model instances are communicated via binding and/or collection change events.Once the user has viewed each page at least once, all page views are instantiated and happily listen to update events.Which in effect means that each time a model instance changes, all interested views receive that event and compute derived data or trigger item-renderers.I have tested and confirmed this behaviour in a proof-of-concept application. Even when setting a list to being invisible, it still listens to collection change events and invalidates any renderer affected.What would you do?
I'm trying to create a for loop to set the color objects outlineColor1...100 to the value defined in variable _root.outlineCol. Everything works fine when I set the color to these objects via 100 lines of code but I'd like to replace them with a for loop of course. I suspect the syntax in the first part of the second line is incorrect but I'm not sure.
for (var i:Number = 1; i <= 100; i++) { outlineColor[i].setRGB(_root.outlineCol); trace(i); }
i am having a problem removing objects from the stage and their associated arrays. basically when a "shark" is added to stage i want all "cans" to be removed and i dont want any "cans" to be added until the shark has left.my problem comes as i dont want to keep using for loops as i already have two or three for "cans" alone and i heard thats not good for the code!
Code: var canTimer:Timer=new Timer(2000); canTimer.addEventListener(TimerEvent.TIMER, addCan); canTimer.start();
[code]....
im not 100% sure were to put this in my code-i didnt really want to put it in a function of it's own as it would mean using another for loop?i get a output error when a shark is added like this:
Quote:
TypeError: Error #2007: Parameter child must be non-null. at flash.display:isplayObjectContainer/contains() at dolphinmoviegame_fla::MainTimeline/canHitTest()
I have 4 objects that I all want to have their own velocities. I have a bunch of variables (each one has a different value): PHP Code: public var vx1:Number;public var vx2:Number;public var vx3:Number;public var vx4:Number;
Rather than having a function for each object to say: PHP Code: function1 { this.x = vx1}function2 { this.x = vx2}function3 { this.x = vx3}function4 { this.x = vx4}
I'd like to have a for loop to have my objects x position to += vx(1 through 4): PHP Code: for (var i:Number=0; i<5; i++) { this.x += (vx+[i]); }
So I tried the above with a combination of " " around different parts of (vx+[i]) but I realized that turning any of it into a string means 'this.x' cannot read it because x has to be a number not a string. So how can I make this.x = vx1 then vx2 and so on with a for loop?
The follow code produces a strawberry image that falls from the top of the screen to the bottom. I tried using a for loop to create 10 different instances of this but it doesn't seem to work for me.(Note: ranx is a number produced randomly earlier in the program)
Code: var nstrawberry:strawberry = new strawberry(); stage.addChild(nstrawberry); nstrawberry.x = ranx;
This piece of code gives me an error because i have an equation on the left side of the equal sign, logically it makes sense, but flash doesn't like the code how would i do some thing like this?[code]
I'm trying to get something quite simple to work, but can't figure out what's happening here. I have five identical MCs (Bat characters), and the user can drag a bottle to feed them.
There is a hittest object (called WormEat) inside the bat's head. When the bottle, which is attached to the cursor touches the bat's head, it toggles to frame 2 of the bottle, which should play an animation of the liquid going down to empty.
This code is all working fine, except that when the code toggles to frame 2 of the bottle, it remains static. The animated Movie Clip doesn't play.
If not, perhaps a Switch statement could work, but I'm not sure how to use that method with Hittest..
Code: var DragArray:Array = [Bat1, Bat2, Bat3, Bat4, Bat5]; for (var i:int = 0; i < DragArray.length; i++) { DragArray[i].addEventListener(Event.ENTER_FRAME, CollisionWorm);
I have a character whose face I'm trying to change. The face is a Bitmap object that gets loaded at runtime and placed into the characters face holder movieclip.
I'm loading the Bitmaps just fine, but there is a snag.
The character has many animation states, each of them is a movieclip that lives in it's own frame in the main character movieclip (so that each frame is an animation state).
The problem lies in that the face holder movieclip is inside each state animation movieclip, and it itself is animated along with the character (it's a face, it has to move along too...)
On each state movieclip I have an instance of the faceholder placed on the timeline, and from the character class I can access it by going this.mc.face (where 'mc' is the current state movieclip -they're all structured the same way and have the same objects inside)
So, after I load my image for the face, I'm going like this:
this.mc.face.addChild(faceImg);
this does load the face into the faceholder, and it stays there for a while... until the timeline loops back and the instances reset themselves.
So, I'm kinda stumped here... and feeling rather stupid since this should have been simple... How can I keep the faceHolder movieclip from resetting itself when the timeline loops?
To make things worse, I've realised that the faceholder resets itself not only at each timeline loop, but at each keyframe...
I don't think running a function on EnterFrame just to keep placing the face there again is a good idea... (sounds like disaster really) but then again, it might be the only way, since each state movieclip has it's own set of keyframes :P
EDIT: I just tried the above idea of replacing the image on each frame, but even that doesn't work... the face flickers with a null object error at every loop... go figure why... the face holder movieclip has a motion tween that spans all the range on the timeline... it never gets replaced by a blank frame.
In a Flex project, I have an array with objects in it. I want to save this array in a cell on a mysql table along with some other basic info like title, and an id. How to echo all the rows... I'm trying to echo the contents of an array that was serialized and placed in a single cell. This array has objects in it. So, I have this code here to serialize the array, and insert it along with the other info into my DB:
function submitLogDbObj($array,$id,$title) { $title=mysql_real_escape_string($title); return mysql_query("INSERT INTO logs (text,id,title) VALUES ('".serialize($array)."','$id','$title')"); }
Then for a test I'm trying to make a loop that will display the log in a way that looks like a conversation... An object in my array would look something like: [1] icon = "" msg = "this is a test" name = "Them: " systemMsg = 0 [Code] .....
I need to be able to make a large amount of concentric circles, using only the action script. I need to be able to alter each of these concentric circles independently from each other. Currently My code is as follows:
ActionScript Code: var circ1:MovieClip = new MovieClip(); addChild(circ1);
I've been working on this for over 3 hours and it is about to drive me crazy! I was one of those people who never paid attention to math in high school because i thought i would never use it ( i knew i wanted to be an artist/designer of some sort). But now of course, that attitude is coming back to haunt me. I'm using a for loop to place several objects on stage. I need a formula that will space objects along the x axis evenly, and center all the objects on the stage. Kinda like if you use the align panel in flash to distibute the vertical centers of several objects to the stage, if that makes sense. If there is only one item, it should be directly in the center of the stage. If there are 2, it should place them in the center of the 2 halves of the stage, and so on for howeve many objects there are. I also want a buffer of about 25 pixels on either edge of the stage so that no object is ever on the very edge of the stage. I made a simple diagram to illustrate:
a little while ago I saw something on this website:[URL]...I decided I wanted to recreate something like it.
They're using javascript, I'm using ActionScript, anyway.I'm trying to create collision detection for an array of movieclips inside a for loop. Right now I have it that upon holding down the mouse, the same movie clip will fall onto a ground object (and bounce up occasionally,) I'm trying to make it to so each ball could stand on top of each other. I've used collision detection before for separate objects, but never for instances of the same object inside a for loop.
I am trying to create a card game (deck of 24 cards/6 cards will be dealt to the stage at one time (3 arrays)).
I want 6 cards to be dealt to the stage when you click the "Deal" button. I think i have the loop set up properly, the first array traces, however i can't get the cards to be added to the stage. What am i doing wrong? Once i get the first set of cards to be built to the stage, i will want to remove the previous set and the second set will be dealt to the stage once the "Deal" button is clicked again.
//code var aArray = new Array(); aArray[0]=Card1; aArray[1]=Card2;
I create some movieclips dynamically through a loop and store them into an array. I add an event listener to all those movieclips. In the function to which I direct the listener I want to be able to get the loop variable value associated with each movieclip. For example if you click the movieclip that was created the first time the loop ran then you would get the value 0.
Hope I have explained myself well enough. Is it necessary to create a custom event class for this?