ActionScript 3.0 :: Socket Event Triggers Movieclip Movement - Need More Frequent Rendering
May 11, 2009
I have a flash project that's implementing a simple two player game. I have added an enterFrame function to my main movie which listens for keyboard activity in order to move a cowboy gunslinger. Whenever the cowboy moves, I send a message over a socket to a server which dispatches the movement to the other connected client. This works pretty well, however, the movement messages tend to arrive in clumps which results in jumpy animation of my cowboy on my opponents screen and jumpy animation of his cowboy on my screen. To illustrate, i put a trace in my enterFrame function because I am imagining that this function will run roughly once each time my main movie renders the screen. I also put a trace statement in my function that responds to network traffic and moves the remote player's cowboy on my screen. Here's the output:
I have a flash project that's implementing a simple two player game. I have added an enterFrame function to my main movie which listens for keyboard activity in order to move a cowboy gunslinger. Whenever the cowboy moves, I send a message over a socket to a server which dispatches the movement to the other connected client. This works pretty well, however, the movement messages tend to arrive in clumps which results in jumpy animation of my cowboy on my opponents screen and jumpy animation of his cowboy on my screen. To illustrate, i put a trace in my enterFrame function because I am imagining that this function will run roughly once each time my main movie renders the screen. I also put a trace statement in my function that responds to network traffic and moves the remote player's cowboy on my screen.
Here's the output: enter frame:4 enter frame:4 enter frame:4 client movePlayer running client movePlayer running client movePlayer running [Code] .....
As you can see, I'll get several messages in a row from the remote client which instruct me to move their cowboy ('client MovePlayer running') and they will all run in a row before the screen updates. I'm guessing I should be using something like updateAfterEvent but this method is only provided by Mouse, Timer, and Keyboard events.
So a few questions: 1) Can someone recommend a good approach to force a screen render each time an incoming movePlayer event arrives over the socket? It's important to note that my function for handling these events has no visibility to the original socket data event. 2) Am I right in understanding that the enterFrame function of my main movie happens once each time my movie is rendered? Is there some more accurate event to which I could attach a trace message so that I better understand the relative frequency of the render events and the socket events? 3) Does firing an updateAfterEvent call force onEnterFrame events to happen more frequently? I'm worried about destroying performance by inadvertently firing more enterFrames which would fire more socket events which would fire more enterFrames, etc., etc.
I have a few external audio clips in MP3 format that I bring in to my SWF by creating different Sound Channels for them. However what I would like to do it when the end of the MP3 file is reached, it will dispatch an event to make the playhead on the main timeline move to a certain frame.
I am working on a game project and i have a question about movie clip movement using keyboard event. Basically I have a character on screen and it can move on the x axis using the left and right buttons. I am making my character move by changing the x value of the character movieclip but I find very it laggy and not smooth and if I am going point by point then it's too slow. Whats the best way to make the character move so that the transition will be smooth.
I'm using FLCS4 (AS3) and I've built a very basic site, simple pages on various frames. Three of the frames/pages contain video components that auto-play a flv clip.What I'm asking is it possible to know when the video clip is finished and at that point display a button.(So the user cant proceed forward until the video clip is finished playing){captive audience, so to speak}Anyways, is this possible, if so; how do I approach it?
it loads an external .swf file and is supposed to play it. I've added an event listener to run when the file is loaded. The function it calls moves the video to the bottom most layer so the buttons still show and then plays the file. The problem is the event listener never triggers.
I have a wheel that the user can spin by flicking it with a mouse (think wheel of fortune). It needs to trigger an event once the spinning has finished depending on what section of the wheel it has landed on. I can get it to trigger an event but it triggers every time the wheel passes the hitTest object, not just when it is done. I've attached a sample of it.
I have a component called X. I'm trying to make a menu come down from it when I put my mouse over it.
I have a mouseOver handler which changes the component's state to another state which shows an extra child component (the menu) on the lower part. This of course makes the X component grow.
I also have mouseOut event handler which makes the menu disappear by returning component X to its original state.
When I move the mouse over the component the menu appears as expected. But when I move the mouse down to the menu that is now visible, as soon as I touch it, it disappears. This way it's impossible to reach the menu.
I guess the mouseOut event is triggered as soon as I move out of the old boundaries. Is this so? And how can I avoid it? The new boundaries should now consider the extra child with the menu.
Could someone explain when does local SharedObject triggers event handlers added via addEventListener?I have tried and it doesn't trigger, after flushing.For example i have two object.swf both in separate browser tabs.I'm adding data inside object.swf on one tab and want event to be triggered in object.swf from another tab.Is it possible with native functionality and without remote type of SharedObject?Ofc i could write infinite loop and check local storage for changes, but it's the last solution i would like to implement.I was reading docs and played with example over there, but it doesn't trigger event, even if it is added before flushing.[code]
This image shows the problem, the 3 is a PNG image with a nice drop shadow that expands quite far from the white square. It is a movieclip which was added by the square movieclip.This obviously changes the size of the movieclip so the ROLL_OVER will trigger whenever the mouse is over either of these objects.My question is, how would I make the movieclip "3" never trigger any sort of mouse event for its parent?
Things that do not work: mouseEnabled = false; (why doesn't this work?? ugh) mouseChildren = false;
I'm using a spark list to render data which I get from a web service.is there an event which fires after the list has finished rendering all the data ?I want to show a loading image to the user until the list finishes.
I have a button and when its clicked its call a function, that calls loginData.send and does a little IF condition, that IF condition relies on the data returned by loginData.The condition doesn't work because its called right next to the loginData.send, and .send method still didn't returned the values from the XML file. But if you click it a second time a second after the first click the IF condition works.So to deal with i wanted to do a eventListener so that when loginData.send returned the data from the XML it fires up the IF condition. But i don't know how to do it.
I've been reading up on GC in AS3, I understand how it works now, and how I should go about things, nullifying all references, weak references, avoiding circular references etc (I tend to have circular references now I think about it).
How does the GC in AS2 work in comparison? How often is GC activated in both environments?
And is performance the reason that the AS3 GC has become less automatic and less frequent?
In AS2 presumably it's having to do far more scans and more frequently, thus being more of an overhead?
How does the delete keyword differ in AS3 compared to AS2? I know many people used null in AS2. I tended to use delete for onEnterFrame events and instances of classes no longer being used, then just remove for movieclips obviously.
I've been working with Flash CS5 for the last few months, using it for animation, on an iMac 2.0Ghz, 1GB RAM, Mac OS 10.6; Once the files start becoming heavy Flash starts acting up, crashing frequently, freezing up, and takes too long to save (almost a minute or more!) I've been told that Adobe products aren't working 100% with Snow Leopard; is this normal? i have all the updates, both from Apple and Adobe; Is there any kind of bug fix, any of the sort that I can download?
i have a set of thumbnails which loads videos from a xml filebut the problem is that when i click on thumbs the video seems to get loaded in front of everything. The swf shows correctly but local dosent'..and the funny thing is that wen i resize the movie in html ,movie loads in front hiding the thumbs.
I've decided to make a start on a new platformer and I was wondering specifically how each of you programmers would go about handling multiple frequent collisions between the player and level/environment. At the moment I'm quite proud of this [URL] Here the player is using a single if statement as follows to check for hit detection.
handling multiple frequent collisions between the player and level/environment. At the moment I'm quite proud of this [URL]. Here the player is using a single if statement as follows to check for hit detection.
(This has a slight problem as the player can only be touching one ground at any time and this loops through all of them it ends up making the player fall through the ground anyway.)
When I send number (int)52 s.Send(BitConverter.GetBytes((int)872415232));, flash show me trace(socket.readInt()); 872415232 If i send 872415232, flash show 52.Why? And how it fix?
I thought I saw somewhere that you could set a listener to monitor a MovieClip's position, to see if it has been moved. Is this possible in as2? Only as3? Do I just have a loose screw?Or is there an event that triggers when a MC is dragged (not pressed, not dragged out, but dragged around)?
I could've moved on to the more difficult stuff: collision detecting and course plotting.I have spent over 2 hours just trying to get a MovieClip to move from A to B -- or from x,y to x,y I should say.I first thought I could just set new x, y properties for my MC, and then it would move there. No.Then, I tried using an event handler and function. This worked, but after the first "leg" of the movement, it sent me a 1063 error, and I also was concerned that the Event I used (ENTER_FRAME) was a one-time use kinda thing.{{What IS the proper Event to call, when you just want the computer to act on its own?? No mouse CLICK, no keyboard UP -- just move, doggone it!}}
Then I tried several permutations of functions and arrays, but it seems like movement of an MC demands an Event. Is this true? For a while, I fiddled around with my TweenLite commands.I currently have a Guide moving around my Grid, which is -- through TweenLite -- drawing a line.I just want this additional MC to tag along for the ride.Here's the code for the Tween; it's pretty standard:
I tried to duplicate this and apply it to my MC. No dice. It actually shifted my whole stage or something weird.I can just add my MC as a Child to the TweenGuide, and then it will certainly tag along
I am trying to move an object on keypress. so i am doing
if(keyboardevent.keycode == keycode) { code to move; }
this works perfectly fine, but when i keep the key pressed for a couple of seconds, the motion is not smooth. for the first second the object gets stuck there, and then moves smoothly. same thing happens when i change the key. basically, it is taking time to read the first key event.
why is it so? i dont want this 1 second delay. i want the object motion to be fluent, as i am making a time critical game.
Is there any way to know if data is completely received on the other end of a flash.net.Socket? Like a complete event? Based on the event documentation there is none. If there is no way, what are the alternative strategies?
I have made a movieclip and gave the frame this actionscript:
------------------------------------------------------------ var keyListener:Object = new Object(); keyListener.onKeyDown = function() {[code]........
it moves fine and stuff but i was wondering how can i restrict the area in which the movieclip can actually move ? my flash file is 550px X 400px and i want to make it so that it can only move in 300px X 200px of the file if you understand ?
I've attached a demo fla so you can see what I'm trying to do. Basically the big circle is a spaceship that will move to wherever you click. The small circle is a resource that the ship can collect, in this case it's called iron. When you click on the iron the ship moves to it and then the small circle disappears, and +1 is added to your inventory, creating the illusion that the ship has collected it. Problem is, after you collect the iron, you can't really move the ship anymore. It's stuck around the position where the iron was. How do I regain control of the ship after I collect the iron?
I have a graphic of a computer with a mouse that is a movieclip and I am wondering if it is possible to be able to move the movie click about by clicking and dragging on it but I want to restrict the mouse to a certain space so it doesn't float off the table.
I have a background image that moves left and right, continuously giving a 360 Degrees appearance. My control buttons work fine but what I want to do is ease in to the movement. Here is a LINK to my demo. When you roll over the arrows is simply starts and stops. I'd like to ease the starts and stops
Right Arrow Code: on (rollOver) { _root.theclip2.gotoAndPlay(_root.theclip2._currentframe); } on (rollOut) { _root.theclip2.stop(); [Code] .....