XMLSocket in AS3

poor old lowmoose here is having problems with XLMSocket() in
AS3:
http://board.flashkit.com/board/showthread.php?t=736240
me too, i've got very similar problems and reading about the
trouble lowmoose had i'm wondering: is XMLSocket in AS3 a bit
broken? AS3 is reasonably new and i can't imagine many people will
have had experience of using XMLSocket yet so its not out of the
question that it might have a few bugs that havenn't been
discovered yet.
without going into tremedous detail an application that was
sending and receiving multiple asynchonous data thru an xmlsocket
in AS2 was working fine. the same app, same code, but in AS3 is not
working fine.
can i please ask these two questions
AS3 users: have you had similar problems with XMLSocket in
AS3 and if so can you please tell us about them?; and
AS3 developers: are there known issues with XMLSocket in AS3
and if so could you share them with us please?
because i need to decide very quickly about whether i should
rollback to AS2 or not.....
thank you! :)

What is your sandbox set to? "Access local files only" or "Access network only"? It should be set to network once it's live, however 127.0.0.1 is obviously a local loop so you could be getting snagged with that. Try flipping between those sandboxes.
Also open up TCP on the ports you need if you're using a software firewall.

Similar Messages

  • XMLSocket - Adobe ActionScript 3 (AS3 ) API Reference

    This question was posted in response to the following article: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/XMLSocket.htm l

    There is no ProgressEvent discpathing from XMLSocket, right?
    So this is not needed: dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);

  • Trouble with socket gateway and an as3 xmlsocket connection

    I succesfully set up the socket gateway and am able to conect to the CF socket gateway and send data from flash to the gateway.
    The error I keep getting is when I add return value to the "onIncomingMessage"... cf error always logs "Cannot send outgoing message. OriginatorID "123124124" is not a valid socket id.
    I am passing the originatorID as in the docs.... my question is what is a valid originatorID?
    <cffunction name="onIncomingMessage" output="no">
    <cfargument name="CFEvent" type="struct" required="yes">
    <!--- Create a return structure that contains the message. --->
    <!--- Get the message. --->
       <cfset message="#CFEvent.Data.message#">
       <!--- Where did it come from? --->
       <cfset orig="#CFEvent.OriginatorID#">
    <cfset retValue = structNew()>
    <cfset retValue.OriginatorID = orig>
    <cfset retValue.MESSAGE = message>
    <!--- Send the return message back. --->
    <cfreturn retValue>
    </cffunction>
    I really hope I can get an answer hardly any docs or anything online on how to correctly return a message via a socket gateway.
    Thank you.

    I succesfully set up the socket gateway and am able to conect to the CF socket gateway and send data from flash to the gateway.
    The error I keep getting is when I add return value to the "onIncomingMessage"... cf error always logs "Cannot send outgoing message. OriginatorID "123124124" is not a valid socket id.
    I am passing the originatorID as in the docs.... my question is what is a valid originatorID?
    <cffunction name="onIncomingMessage" output="no">
    <cfargument name="CFEvent" type="struct" required="yes">
    <!--- Create a return structure that contains the message. --->
    <!--- Get the message. --->
       <cfset message="#CFEvent.Data.message#">
       <!--- Where did it come from? --->
       <cfset orig="#CFEvent.OriginatorID#">
    <cfset retValue = structNew()>
    <cfset retValue.OriginatorID = orig>
    <cfset retValue.MESSAGE = message>
    <!--- Send the return message back. --->
    <cfreturn retValue>
    </cffunction>
    I really hope I can get an answer hardly any docs or anything online on how to correctly return a message via a socket gateway.
    Thank you.

  • Establishing a socket connection between a .swf file and a socket-test program (TCP/IP builder - Windows), in AS3.

    I have an issue with a college project I'm working on.
    Using Actionscript 3, I made a simple .swf program, an animated, interactive smiley, that 'reacts' to number inputs in a input-box.
    For the sake of the project, I now need to make the framework for establishing a socket connection with the smiley .swf, and another program.
    This is where I encounter issues. I have very little knowledge of AS3 programming, so I'm not certain how to establish the connection - what's required code-wise for it, that is.
    To test the connection, I'm attempting to use the "TCP/IP builder" program from windows, which lets me set up a server socket. I need to program the .swf file into a client - to recognize it, connect to it, then be able to receive data (so that the data can then be used to have the smiley 'react' to it - like how it does now with the input-box, only 'automatically' as it gets the data rather than by manual input).
    My attempts at coding it are as follows, using a tutorial (linked HERE):
    //SOCKET STUFF GOES HERE
        var socket:XMLSocket;        
        stage.addEventListener(MouseEvent.CLICK, doConnect); 
    // This one connects to local, port 9001, and applies event listeners
        function doConnect(evt:MouseEvent):void 
        stage.removeEventListener(MouseEvent.CLICK, doConnect); 
        socket = new XMLSocket("127.0.0.1", 9001);   
        socket.addEventListener(Event.CONNECT, onConnect); 
        socket.addEventListener(IOErrorEvent.IO_ERROR, onError); 
    // This traces the connection (lets us see it happened, or failed)
        function onConnect(evt:Event):void 
            trace("Connected"); 
            socket.removeEventListener(Event.CONNECT, onConnect); 
            socket.removeEventListener(IOErrorEvent.IO_ERROR, onError); 
            socket.addEventListener(DataEvent.DATA, onDataReceived); 
            socket.addEventListener(Event.CLOSE, onSocketClose);             
            stage.addEventListener(KeyboardEvent.KEY_UP, keyUp); 
        function onError(evt:IOErrorEvent):void 
            trace("Connect failed"); 
            socket.removeEventListener(Event.CONNECT, onConnect); 
            socket.removeEventListener(IOErrorEvent.IO_ERROR, onError); 
            stage.addEventListener(MouseEvent.CLICK, doConnect); 
    // Here, the flash tracks what keyboard button is pressed.
    // If 'q' is pressed, the connection ends.
            function keyUp(evt:KeyboardEvent):void 
            if (evt.keyCode == 81) // the key code for q is 81 
                socket.send("exit"); 
            else 
                socket.send(evt.keyCode); 
    // This one should handle the data we get from the server.
            function onDataReceived(evt:DataEvent):void 
            try { 
                trace("From Server:",  evt.data ); 
            catch (e:Error) { 
                trace('error'); 
        function onSocketClose(evt:Event):void 
            trace("Connection Closed"); 
            stage.removeEventListener(KeyboardEvent.KEY_UP, keyUp); 
            socket.removeEventListener(Event.CLOSE, onSocketClose); 
            socket.removeEventListener(DataEvent.DATA, onDataReceived);
    Trying to connect to the socket gives me either no result (other than a 'connection failed' message when I click the .swf), or the following error:
    Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: file:///C|/Users/Marko/Desktop/Završni/Flash%20documents/Smiley%5FTCP%5FIP%5Fv4.swf cannot load data from 127.0.0.1:9001.
        at Smiley_TCP_IP_v4_fla::MainTimeline/doConnect()[Smiley_TCP_IP_v4_fla.MainTimeline::frame1:12] 

    Tried adding that particular integer code, ended up with either errors ("use of unspecified variable" and "implicit coercion") , or no effect whatsoever (despite tracing it).
    Noticed as well that the earlier socket code had the following for byte reading:
    "sock.bytesAvailable > 0" (reads any positive number)
    ...rather than your new:
    "sock.bytesAvailable != 0" (reads any negative/positive number)
    Any difference as far as stability/avoiding bugs goes?
    So then, I tried something different: Have the program turn the "msg" string variable, into a "sentnumber" number variable. This seemed to work nicely, tracing a NaN for text (expected), or tracing the number of an actual number.
    I also did a few alterations to the input box - it now no longer needs the 'enter' key to do the calculation, it updates the animation after any key release.
    With all this considered and the requirements of the project, I now have a few goals I want to achieve for the client, in the following order of priority:
    1) Have the "sentnumber" number variable be recognized by the inputbox layer, so that it puts it into the input box. So in effect, it goes: Connect -> Send data that is number (NaN's ignored) -> number put into input box -> key press on client makes animation react. I optionally might need a way to limit the number of digits that the animation reacts to (right now it uses 1-3 digit numbers, so if I get sent a huge number, it might cause issues).
    - If the NaN can't be ignored (breaks the math/calculus code or some other crash), I need some way of 'restricting' the data it reads to not include NaN's that might be sent.
    - Or for simplicity, should I just detect the traced "NaN" output, reacting by setting the number variable to be "0" in such cases?
    2) After achieving 1), I'll need to have the process be automatic - not requiring a keyboard presses from the client, but happening instantly once the data is sent during a working connection.
    - Can this be done by copying the huge amounts of math/calculus code from the inputbox layer, into the socket layer, right under where I create the "sentnumber" variable, and modifying it delicately?
    3) The connection still has some usability and user issues - since the connection happens only once, on frame 1, it only connects if I already have a listening server when I run the client, and client can't re-connect if the server socket doesn't restart itself.
    I believe to do this, I need to make the connection happen on demand, rather than once at the start.
    For the project's requirement, I also need to allow client users to define the IP / port it's going to connect to (since the only alternative so far is editing the client in flash pro).
    In other words, I need to make a "Connect" button and two textboxes (for IP and port, respectively), which do the following:
    - On pressing "Connect", the button sets whatever is in the text boxes as the address of the IP and port the socket will connect to, then connects to that address without issues (or with a error message if it can't due to wrong IP/port).
    - The connection needs to work for non-local addresses. Not sure if it can yet.
    - On re-pressing connect, the previous socket is closed, then creates a new socket (with new IP/port, if that was altered)
    It seems like making the button should be as simple as putting the existing socket code under the function of a button, but it also seems like it's going to cause issues similar to the 'looping frames' error.
    4) Optional addition: Have a scrolling textbox like the AIR server has, to track what the connection is doing on-the-fly.
    The end result would be a client that allows user to input IP/Port, connects on button press (optionally tracking/display what the socket is doing via scrollbox), automatically alters the smiley based on what numbers are sent whilst the connection lasts, and on subsequent button presses, makes a new connection after closing off the previous one.
    Dropbox link to new client version:
    https://www.dropbox.com/s/ybaa8zi4i6d7u6a/Smiley_TCP_IP_v7.fla?dl=0
    So, starting from 1), can I, and how can I, get the number variable recognized by "inputbox" layer's code? It keeps giving me 'unrecognized variable' errors.

  • Need help with Security when running AS3 inside browser

    Hi,
    I am fairly new to flash, but a fairly experienced
    programmer.
    I have created a game that runs perfectly and communicates to
    a WinSock server over port 4000 to publish its final score to.
    Using simple XMLSocket and Send.
    When I run the game in the standalone flash player everything
    works perfectly as it should
    However when I embed in a HTML page or similar it goes wrong.
    The game works fine, but the final posting to the WinSock socket
    server fails. I have retrieved the error message.
    ioErrorHandler: [SecurityErrorEvent type="securityError"
    bubbles=false cancelable=false eventPhase=2 text="Error #2048"]
    My server is a local server to me running IIS 6. Everything
    runs fine by the standalone flash player so I know ports are clear
    and firewalls are not the problem.
    Searching around google and forums I have found out that in
    9,0,124,0 (the flash I am running) that they made some security
    enhancements, namely you need to post a crossdomain file.
    My file is sat in the wwwroot of my webserver where my flash
    swf is hosted and looks like
    <cross-domain-policy>
    <allow-access-from domain="*" secure="false"/>
    </cross-domain-policy>
    I have also tried adding the following to the 1st section of
    the swf file
    Security.loadPolicyFile("
    http://mydomainname.com/crossdomain.xml");
    I have tried all conbinations, but I cannot get the flash to
    communicate to the socket server when it inside a web browser.
    If i run it in the standalone player, everything works
    perfectly.
    Can someone help me please. I have been googling and ripping
    my hair out for ages. This is the final stage of my project and I
    am failing at the final step.
    Just to add.
    My server and testing computer are on the same domain, the
    web server is a win2003 server and my testing and coding server is
    a XP machine running IE7. They are linked by a ADSL router sharing
    the same external IP address but via DHCP addressing. Everything
    works fine for port forwarding of the winsocket port.
    Just to emphasis, I believe this setup is correct, as it all
    works fine when I run in the flash player.
    Many thanks

    I fixed it eventually.
    In flash 9.0.124.0 they now force you to have a socket XML
    server running on port 843 a server somewhere if you wish to use
    XMLSocket inside a browser.
    Nothing to do with domain or crossdomain.xml files.
    You need to also call
    Security.loadPolicyFile("xmlsocket://x.x.x.x:843") before you
    open the socket.
    to load in the XML that defines what is allowed.
    Search google for AS3 and socket server port 843 and you will
    find examples and even a simple Java based server to use.

  • LoadPolicyFile on xmlsocket problem

    Hi,
    I have some strange problem regarding the security settings
    in Flash Player. I'm using AS3 to connect to port 80 on my server.
    Because this is only allowed after downloading a policy file, I'm
    calling
    Security.loadPolicyFile("xmlsocket://"+_httpServer+":20");
    just before
    socket.connect(_httpServer, _httpPort);
    On my server I tell inetd to listen on port 20 and start the
    following bash script after a connection has been established:
    #!/bin/bash
    read
    printf '<?xml version="1.0"?><!DOCTYPE
    cross-domain-policy SYSTEM "
    http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"><cross-domain-policy><allow-access- from
    domain="*" to-port="80" /></cross-domain-policy>\00'
    exit
    My app doesn't work, though. I notice, that a connection is
    opened to port 20 and that the policy file is sent to the Flash
    Player. But then nothing happens. No exception, no error, and I'm
    already using the debug version of the Player.
    Has anyone already successfully established a socket
    connection after loading a policy file from another port via
    "xmlsocket://"? Or am I completely wrong with the way my bash shell
    script is handling the connection? Any ideas?
    Thanks in advance
    Mycroft.

    So I switched from XMLSocket to just plain Socket.
    I have this now:
      var sock:Socket = new Socket();
                sock.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
                sock.connect("localhost", 7778);
                sock.writeUTFBytes(xmlMsg);
                sock.flush();
    But nothing gets transmitted unless I close the Flex app.
    I don't get this. What seems to be a problem?
    I read an API docs twice and it says that writeUTFBytes (or any other write methods) are just putting stuff in a buffer
    the flush() is the one that signals that the buffer content needs to be sent.
    I'm doing just that and still I get nothing on the other side unless I close the Flex app.
    Any suggestion?
    Thanks
    Greg

  • Photo gallery in as3

    I'm making photo gallery where photos will be loaded from external xml file but i have problem. I want to add an effect when photo is changing like on this site: http://www.studiomelon.pl/index.html#/1/  Could somebody help me with that? I am noob in flash so please explain it as clear as you can. Thanks.

    I was sesrching for that for a long time before i created this tread. There is many tutorials and exaple files for page flip or page turn but i cant find good one. Many of them was coded in as1 or as2 other using php and java script so its difficult  to understant. I just want one simple solution for that. It cant be so hard to create something like that. Could you help me to find some good and simple tutorial in as3?

  • Creating an "if" Statement in AS3

    I've been having a problem trying to implement 2 email forms in the same scene at different places in the timeline.  If I do just one form, there isn't a problem, but there is a problem with the 2nd form (I've tried using different instance names to no avail). However, it appears I have most of it figured out, but am still having a problem, which I believe I may have a solution for by using an "if" statement.  In the following AS3 code is a string that reads var URL_request:URLRequest = new URLRequest( "send_email.php" ); I believe I may be able to resolve the problem if I had a 2nd string (in the same code) that read var URL_request:URLRequest = new URLRequest( "send_email_02.php" ); Is there a way to include that string in the same AS3 by using an "if" statement telling the code to "submit" the 2nd form?  If so, could someone please give me an example of how to write that "if" statement? This form has been driving me nuts for 4 days now and any help would be greatly appreciated. Thank you.
    stop();
    contact_name.text = contact_email.text = contact_subject.text =
    contact_message.text = message_status.text = "";
    send_button.addEventListener(MouseEvent.CLICK, submit);
    reset_button.addEventListener(MouseEvent.CLICK, reset);
    var timer:Timer;
    var var_load:URLLoader = new URLLoader;
    var URL_request:URLRequest = new URLRequest( "send_email.php" );
    URL_request.method = URLRequestMethod.POST;
    function submit(e:MouseEvent):void
    if( contact_name.text == "" || contact_email.text == "" ||
      contact_subject.text == "" || contact_message.text == "" )
      message_status.text = "Please complete all text fields.";
    else if( !validate_email(contact_email.text) )
      message_status.text = "Please enter a valid email address.";
    else
      message_status.text = "sending...";
      var email_data:String = "name=" + contact_name.text
            + "&email=" + contact_email.text
            + "&subject=" + contact_subject.text
            + "&message=" + contact_message.text;
      var URL_vars:URLVariables = new URLVariables(email_data);
      URL_vars.dataFormat = URLLoaderDataFormat.TEXT;
      URL_request.data = URL_vars;
      var_load.load( URL_request );
      var_load.addEventListener(Event.COMPLETE, receive_response );
    function reset(e:MouseEvent):void
    contact_name.text = contact_email.text = contact_subject.text =
    contact_message.text = message_status.text = "";
    function validate_email(s:String):Boolean
    var p:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
    var r:Object = p.exec(s);
    if( r == null )
      return false;
    return true;
    function receive_response(e:Event):void
    var loader:URLLoader = URLLoader(e.target);
        var email_status = new URLVariables(loader.data).success;
    if( email_status == "yes" )
      message_status.text = "Success! Your message was sent.";
      timer = new Timer(500);
      timer.addEventListener(TimerEvent.TIMER, on_timer);
      timer.start();
    else
      message_status.text = "Failed! Your message was not sent.";
    function on_timer(te:TimerEvent):void
    if( timer.currentCount >= 10 )
      contact_name.text = contact_email.text = contact_subject.text =
      contact_message.text = message_status.text = "";
      timer.removeEventListener(TimerEvent.TIMER, on_timer);

    While the overall scenario isn't all that clear to me, you don't necessarily need an if statement, but just have the different submit buttons assign the different URL_request values before they intiate any other processing.

  • Help with a preloader in AS3

    Hi,
    I upload a website and I have problems with the preloader did it in AS3. It starts after two or three minutes. I have a MC with an animation of 100 frames and the dynamic text of the percent. The preloader is located in the 1 frame to the 10, I mean, first frame with the actions and the other three layers (text, MC and background) with a lenght of 10. The movie has 525 frames. Here is the code:
    stop();
    addEventListener(Event.ENTER_FRAME, lodeando);
    function lodeando(event:Event):void
              var bytesTotales = stage.loaderInfo.bytesTotal;
              var bytesCargados = stage.loaderInfo.bytesLoaded;
              var porcentaje = Math.round(bytesCargados * 100 / bytesTotales);
              textoPorcentaje.text = porcentaje + "% Cargados";
              cargaAnimada_mc.gotoAndStop(porcentaje);
              if (bytesCargados == bytesTotales)
                        removeEventListener(Event.ENTER_FRAME, lodeando);
                        gotoAndPlay(2);
                        textoPorcentaje.text = "";
                        removeChild(textoPorcentaje);
                        removeChild(cargaAnimada_mc);
    Please, Could you help me?.

    These screen captures show the library of the movie. As you can see I export the most of them. However I have doubts about if I must convert to symbol the graphics. I have the preloader in the "presentación" folder without any exportation.
    Please, Could you correct the website?. Please, tell me an e-mail address and I send you the website via WeTransfer.

  • Text input action AS3

    I have a text input field on the timeline that I want the user to enter specific information in. When that information is correctly entered, I need the timeline to progress.
    I successfully used the following AS2, but I cant find corresponding code for AS3
    on (keyPress "x") {
    gotoAndPlay("s05");
    Any help on converting this function to AS3 is greatly appreciated.

    You can use an Event.CHANGE listener for the textfield and then test its value in the event handler function to see if it agrees with the required string...
    inputtField.addEventListener(Event.CHANGE, testEntry);
    function testEntry(evt:Event):void {
         if(inputField.text == "whatever"){
              // do stuff

  • New to Flash AS3, Need help with some weird issues, have .fla link attached...

    Basically, the buttons are not visible when siteplan_mc is replayeed after floorplan closes, but they still work. Most things are only working on double click for soe reason, tho I have them to function on click. and the back button only woorks on unit 1 floorplan, tho the code it the same for all floorplans. I have a feeling it has something to do with levels... but I really have no idea... hopefully someone can help!
    thanks in advance,
    Sarah
    http://www.30eastroosevelt.com/RRHA_SITE.fla

    There are at least two things you're doing wrong. You can't go to a frame where something exists for the first time, and immediately do something to it. Like in your playunit functios for example:
    gotoAndStop("unit1")
    unit1_mc.alpha = 1
    unit1_mc hasn't yet drawn itself on stage to have its alpha set, and so there's an error. That is something that was improved in Flash 10, so if you had set the Flash to publish for Flash 10 and not Flash 9, then the floor plans and the back buttons appears ok. It would sometimes work with double clicks because by the second time you clicked, the movieclip now existed. You might be able to do what you want by having all of the room units on frame 1 of the siteplan_mc, and then set their visible to true or false as you need them, instead of doing the gotoAndStop().
    The other problem is that you're trying to set listeners on the Back buttons that don't yet exist. Wait until you're on the frame where the buttons exists, and then set its listener for the mouse click.
    Other things you're doing could be improved too, but really you might want to get together with someone who has done more AS3, to help you become more familiar with how it works.

  • HELP! Uploading AS3 Game to server, no sound and Spacebar doesn´t work HELP!

    Hello, relatively new to AS3 and flash, this is the first time i am publishing anything. We are trying to upload our simple flashgame to our webserver, the game works perfectly fine locally save for one thing. We get an error regarding TLF which says it wont stream or something. So when it gets online, no sounds play and spacebar doesn't work, left and right arrow does work. We have three TLF text fields that are used to update score, lives and show you final score. If i turn these into classical text they stop working.
    Things we have tried: Changing default linkage from RLS to Merged into code, changing the text boxes to classical text(they then stop working), made sure the paths are correct(all files are in the same directory including the .swz file)
    This is the code from the soundclass:
    package 
        import flash.net.URLRequest;
        import flash.media.Sound;
        import flash.media.SoundChannel;
        import flash.events.*;
        public class MySound
            private var bgSound:Sound;
            private var fireSound:Sound;
            private var waterSound:Sound;
            private var earthSound:Sound;
            private var lightSound:Sound;
            private var soundChannel:SoundChannel;
            public function MySound()
                soundChannel = new SoundChannel();
                bgSound = new Sound();
                var req:URLRequest = new URLRequest("BackgroundSound.mp3");
                bgSound.load(req);
                //fire
                fireSound = new Sound();
                var req2:URLRequest = new URLRequest("soundFire.mp3");
                fireSound.load(req2);
                // water
                waterSound = new Sound();
                var req3:URLRequest = new URLRequest("soundWater.mp3");
                waterSound.load(req3);
                // earth
                earthSound = new Sound();
                var req4:URLRequest = new URLRequest("soundEarth.mp3");
                earthSound.load(req4);
                // light
                lightSound = new Sound();
                var req5:URLRequest = new URLRequest("soundLight.mp3");
                lightSound.load(req5);
            public function playBgSound()
                soundChannel = bgSound.play(0, 999999);
            public function stopBgSound()
                soundChannel.stop();
            public function playFireSound()
                fireSound.play();
            public function playWaterSound()
                waterSound.play();
            public function playEarthSound()
                earthSound.play();
            public function playLightSound()
                lightSound.play();
    I can somewhat get that sound can bugg out, but why does spacebar stop functioning? ANy help is greatly appreciated as this has to be delivered in twelve hours(published online) for a school assignment.

    Also might add publishing it locally in my own browser everything works, as does ofcourse playing it in flash itself. Changing from RLS to merged into code stops the error from coming, but doesn´t fix the problem on the server.
    Code from main class related to sound and spacebar:
    import flash.display.*;
        import flash.events.*;
        import flash.ui.Keyboard;
        import flash.text.TextField;
        import flash.media.Sound;
        import flash.net.URLRequest;
        import flash.events.MouseEvent;
        import flash.utils.Timer;
        import flash.events.TimerEvent;
        public class main extends MovieClip
            private var fireTimer:Timer; //delay between shots
            private var canFire:Boolean = true;
            private var mySound:MySound;
            private var bulletSpeed:Number = -450;
              public function main()
                //load sounds
                mySound = new MySound();
            private function playGame(event:MouseEvent)
                gotoAndStop(2);
                // initialize
                myLives = 5;
                myHitsNo = 0;
                weaponType = 1;
                mybullets = new Array();
                enemys = new Array();       
                myScoreTxt.text = "Score: " + myHitsNo;
                myLivesTxt.text = "Lives: " + myLives;   
                fireTimer = new Timer(400, 1);
                fireTimer.addEventListener(TimerEvent.TIMER, shootTimerHandler, false, 0, true);
                stage.addEventListener(KeyboardEvent.KEY_DOWN, listenKeyDown);
                stage.addEventListener(Event.ENTER_FRAME, addEnemy);
                stage.addEventListener(Event.ENTER_FRAME, checkCollision);   
                player = new thePlayer(stage.stageWidth-40, spawnPoint2);// stage.stageHeight/2);
                stage.focus = player;
                addChild(player);
                mySound.playBgSound();
    public function listenKeyDown(event:KeyboardEvent)  // Controls and weapontype selector
                if (event.keyCode == 37) //left
                    player.movethePlayerDown();
                if (event.keyCode == 39) //right
                    player.movethePlayerUp();
    if (event.keyCode == Keyboard.SPACE) //space
                    shootBullet();
                    //soundFX.attachSound("Pistol Fire.wav");
                    //soundFX.start();

  • How to use as3 in flash cs3 to add dynamic text from a text file into a flash file

    let me start out by saying today is my first day of scripting
    in flash.
    I have a text file text.txt
    it contains
    text1=hello world
    can someone please show me how to display this text in a
    flash file
    i have been searching for this for hours and there are
    solutions with flash mx and actionscript 2.0 but i would like to
    see how to do this in as3.
    just a simple frame that loads that file and displays it when
    you test run the program
    much apreciated
    RC

    I'm not up on AS3 yet, but many things are still similar. You
    need to use the LoadVars class to accomplish this, You can find
    information this in Flahs Help>Actionscript>Actionscript
    Language Reference>Actionscript classes.
    rem: the text.txt file and the text.fla file must be in the
    same directory.
    The code will look something like this:

  • AS3 Scripting for Animated GIF

    Hi,
    I am trying to create an animated GIF for a white noise animation (needed for those viewers who don't have access to a Flash player). The SWF version runs perfectly. Currently, all of the AS3 for the bitmapData.noise and bitmapData.palettemap script is in the first keyframe. So, when I export as an animated GIF, I get a white screen in playback.
    I think the problem for the animated GIF is that there are no frames past the first frame. But, I am not sure how to add frames or re-write the AS3 to get a 30 second animated GIF? I tried duplicating the first keyframe into several new keyframes and get error messages. I would appreciate any help.
    Here's the AS3 in the first keyframe that works well for a SWF (previous relevant thread: http://forums.adobe.com/thread/734335?tstart=0):
    var array:Array=new Array();
    for (var i:uint = 0; i < 255; i++) {
    array[i] = 0xffffff * (i % 2);
    var _bitmapData:BitmapData;
    var bDHolder:Sprite = new Sprite();
    _bitmapData = new BitmapData(stage.stageWidth/4, stage.stageHeight/4);
    bDHolder.addChild(new Bitmap(_bitmapData));
    bDHolder.scaleX = bDHolder.scaleY = 4;
    addChild(bDHolder);
    addEventListener(Event.ENTER_FRAME, onSpriteEnterFrame);
    function makeNoise():void {
                _bitmapData.noise(getTimer(), 100, 255, 7, true);
                _bitmapData.paletteMap(_bitmapData, _bitmapData.rect, new Point(0,0), array, array,array);
    function onSpriteEnterFrame(event:Event):void {
                makeNoise();
    var itsNoisy:Boolean = true;
    stage.addEventListener(MouseEvent.MOUSE_DOWN, manageNoise);
    function manageNoise(evt:MouseEvent):void {
         if(itsNoisy){
             removeEventListener(Event.ENTER_FRAME, onSpriteEnterFrame)
         } else {
             addEventListener(Event.ENTER_FRAME, onSpriteEnterFrame)
         itsNoisy = !itsNoisy;
    Kind Regards,

    Jimmy,
    You may (also) try to ask in the (most) relevant Photoshop forum.
    http://forums.adobe.com/community/photoshop

  • How to read a local file using as3 in a flash object in HTML? [urgent]

    My web site contains a flash object.
    I want to use as3 to read some local .txt file
    by getting the user directory of the file.
    i know AIR can support this by sth like:
    File.desktopDirectory.resolvePath
    but when i open a AIR file for this, it seems
    the action cant be run when i embed it in html.
    And i tried to use the above function in a normal
    flash file in the action script.
    But it cant recognize the File. class..
    How can it be done ?
    It's reli urgent,
    please help...
    Thanks !

    a web based flash app can't detect user directories.  you can use the filereference class'es browse method to let the user locate a file in any directory the user wants.  flash can then retrieve the file's name and type.  but, as mentioned before,  flash can't determine the file's directory.

Maybe you are looking for

  • Can I create the family function without a credit card?

    My problem is I have no credit card and want to use the family share function!

  • DAQ Assistant in subvi not updating output to DAQ board with each call...

    Hi All, I am calling a simple subvi that creates a user-defined number of pulses with "Square Waveform.vi."  This square wave (with the given total number of pulses) is then used as an input to a DAQ Assistant controlling an analog output signal on a

  • Issue qty vs receipt qty

    Also can some one explain me the difference between these 2 quantities . And what does these below objects mean: Receipt Quantity - Stock in Transit Issue Quantity - Stock in Transit Receipt Quantity - Total Stock      Issue Quantity - Total Stock Is

  • Xpath condition

    Hi, I need an xpath to convert to uppercase for <Empid> <Name> <FirstName>demo</FirstName> <LastName>test</LastName> </Name> <Empid> Need to check the element FirstName contains Demo ( by converting it to uppercase) I used various type like these: /E

  • Installation drive only partially adhered to

    My PC has a very partitioned drive (for ghost recovery purposes). One feature of that is the C drive is kept free of anything that is not an OS function where-ever possible. When I installed iTunes, I did so to a different partition (the "F drive").