HitTest in As3.0

Hi All,
I have a square object in the middle of circle.
and i  can move square object using up, down, left, riht arrow keys. I need script for when square object touches circle, then it goes to back, I have use for this below code :
var myobjdim:Array=new Array;
    myobjdim.rit=obj.x+(obj.width/2);
    myobjdim.let=obj.x-(obj.width/2);
    myobjdim.tp=obj.y-(obj.height/2);
    myobjdim.bot=obj.y+(obj.height/2);
    if(bg1.hitTestPoint(myobjdim.tp,obj.y, true))
        trace("it's detection");
In above code "myobjdim" is square object and "bg1" is circle object..
Please any body know script for this in AS3 plese tell me.
Thanks,
K Swamy Vishnubhatla,
webdeginer.blogspot.com.

use:
    if(bg1.hitTestObject(myobjdim))
     var ct:ColorTransform=myobjdim.transform.colorTransform;
ct.color=0x000000;
myobjdim.transform.colorTransform=ct;

Similar Messages

  • AS3 to AS3 Drag/Drop Question

    This is a fairly routine drag/drop interaction. The tricky part is when the invisilbe button 'btnInvis10' is clicked, another movieClip, 'dragger' appears and becomes the element being dragged, to be dropped onto 'mSquare'.  AS3 is giving me some problems when I convert the code - really just changing the functions to be AS3 compliant. But I guess it needs more than just converting. Any ideas?
    My AS2 code worked like this:
    dragger._alpha = 0;
    btnInvis10.onPress = function():Void  {
    dragger._alpha = 100;
    dragger.startDrag(true);
    onMouseUp = function ():Void {
    var bOverlap:Boolean = dragger.hitTest(mSquare);
    //trace(bOverlap);
    if (bOverlap) {
      dragger._alpha = 0;
      btnInvis10._visible = false;
      menubar._x = _xmouse;
      menubar._y = _ymouse;
      gotoAndStop(nextFrame());
      bOverlap = false;
    if (!bOverlap) {
      dragger._alpha = 0;
      dragger._x = 412;
      dragger._y = 490;
    dragger.stopDrag();

    Can you show your AS3 attempt as well?
    I figure I should ask if the coding is errant wrt the way you test if bOverlap is true vs false (since it may be as intended).  In the first conditional where it is true, it is set to false, which will cause the condition that follows it to also run since it is now false...
    if (bOverlap) {
      bOverlap = false;
    if (!bOverlap) {
    One last thing... gotoAndStop(nextFrame());  doesn't make sense (to me).  nextFrame does not return a value, so using it as an argument doesn't buy anything.  By itself it will cause the timeline to move to the next frame and stop.

  • External as2 userDrawingTablet into as3

    created a tablet where the user could draw on the pad. i did it a while ago using actionscript 2. now i'm loading it externally into as3. when placed in as3 it seems to be confused as to where the tablet is and draws only on the bottom right and off the page. also have a text function that is not working properly either.
    kind of a random application and random problem, but not sure where else to go with this...
    was just wondering if anyone had done this and had a similar problem?
    thanx

    "submitter" is a movie clip on the main timeline. this code is inside submitter layed out with a mc named "blackboard". blackboard has a mc named "innerBlackboard" inside of it.
    blackboard.clearChalk = function():Void {
        var cl = this._parent._parent.chalkLine;
        this.createEmptyMovieClip("chalkLayer", 0);
        this.chalkLayer.lineStyle(cl.thickness, cl.color, cl.alpha);
        this.drawings = [];
    blackboard.clearText = function():Void {
        this.createEmptyMovieClip("textLayer", 10);
        this.textfields = [];
    blackboard.clearAll = function():Void {
        this.clearChalk();
        this.clearText();
    blackboard.enterDrawMode = function():Void {
        this.innerBlackboard.onPress = this.startDraw;
    blackboard.startDraw = function():Void {
        var x:Number = Math.round(this._xmouse);
        var y:Number = Math.round(this._ymouse);
        var coordinates = [x + "," + y];
        this._parent.currentDrawing = coordinates;
        this._parent.drawings.push(coordinates);
        this._parent.chalkLayer.moveTo(x, y);
        this._parent.onMouseMove = this._parent.drawChalk;
        this.onRelease = function() {
            delete this._parent.onMouseMove;
    blackboard.endDraw = function():Void {
        delete this.onMouseMove;
        delete this.innerBlackboard.onRelease;
    blackboard.drawChalk = function():Void {
        if (this.hitTest(_root._xmouse, _root._ymouse)) {
            var x:Number = Math.round(this._xmouse);
            var y:Number = Math.round(this._ymouse);
            this.currentDrawing.push(x + "," + y);
            this.chalkLayer.lineTo(x, y);
        } else {
            this.endDraw();
        updateAfterEvent();
    blackboard.enterTextMode = function():Void {
        this.innerBlackboard.onPress = this.startText;
    blackboard.startText = function():Void {
        var d:Number = this._parent.textLayer.getNextHighestDepth();
        var x:Number = this._parent._xmouse;
        var y:Number = this._parent._ymouse;
        this._parent.textLayer.createTextField("t" + d, d, x, y, this._parent.width - x, this._parent.height - y);
        var tf:TextField = this._parent.textLayer["t" + d];
        this._parent.textfields.push(tf);
        tf.type = "input";
        tf.multiline = true;
        tf.wordWrap = true;
        tf.restrict = "^'<>";
        tf.setNewTextFormat(this._parent._parent._parent.chalkFormat);
        tf.embedFonts = true;
        tf.text = "Type message";
        Selection.setFocus(tf);
        Selection.setSelection(0, tf.text.length);
        tf.onKillFocus = function() {
            this.type = "dynamic";
            this.selectable = false;
    blackboard.formatEntry = function():String {
        var tf:TextField;
        var d:Object;
        var entryXML    =  "<entry>";
        entryXML        +=         "<text>";
        for (var i:Number = 0; i < this.textfields.length; i++) {
            tf = this.textfields[i];
            entryXML    +=            "<field x='" + tf._x + "' y='" + tf._y + "' text='" + tf.text + "' />";
        entryXML        +=         "</text>";
        entryXML        +=         "<drawings>";
        for (i = 0; i < this.drawings.length; i++) {
            d = this.drawings[i];
            entryXML    +=            "<drawing coordinates='" + d.join("|") + "' />";
        entryXML        +=         "</drawings>";
        entryXML        += "</entry>";
        return escape(entryXML);
    blackboard.clearAll();
    blackboard.innerBlackboard.useHandCursor = false;
    blackboard.width = blackboard._width;
    blackboard.height = blackboard._height;
    draw_bn.onRelease = function() {
        blackboard.enterDrawMode();
        text_bn.gotoAndStop("_Up");
        text_bn.enabled = true;
        this.gotoAndStop("_Down");
        this.enabled = false;
    text_bn.onRelease = function() {
        blackboard.enterTextMode();
        draw_bn.gotoAndStop("_Up");
        draw_bn.enabled = true;
        this.gotoAndStop("_Down");
        this.enabled = false;
    clear_bn.onRelease = function() {
        blackboard.clearAll();
    submit_bn.onRelease = function() {
        var name:String = name_if.text;
        if (name == "" || name == "name (required)") return;
        var email:String = email_if.text;
        if (email == "" || email == "email (required)") return;
        entry = new LoadVars();
        entry.name = name;
        entry.email = email_if.text;
        entry.message = blackboard.formatEntry();
        returnEntry = new LoadVars();
        returnEntry.onLoad = traceReturn;
        entry.sendAndLoad("submitEntry.php", returnEntry);
    function traceReturn() {
        if (this.result == "success") {
            blackboard.clearAll();
    name_if.onSetFocus = email_if.onSetFocus = function() {
        this.text = "";
        delete this.onSetFocus;
    name_if.restrict = email_if.restrict = "^'<>";

  • Switch, Package hitTest

    Hi, I am near the beginning of the learning curve for AS3.
    The little project I have set myself is to create a weekly based calander.
    And for each day I want to add an image that shows the weather.
    I have the images
    I have a prev and next button that scroll the weeks
    I have switch statement that changes the dates and months based on the week number
    I have a circle under each week day called sun_mc, mon_mc  etc for the image to go into them
    All of this is in the Action Frame and is working ok
    In an .as file package I have
    A hitTest that centres the image in the circle for that day
    What I am trying understand now is
    Is how to use the hitTestObject with two arrays. One array will contain reference to the weather images eg sun_mc, cloud_mc, rain_mc, snow_mc. And the other array will refer to the circle mc for each day eg  sun_mc,mon_mc, tues_mc  etc.
    Below is the relevant code
    This line is in the Action Frame
    cloud_mc.target = sun_mc;
    The package file for the DragDrop. At the moment I have it working for a one to one outcome. eg i can drag the cloud_mc to touch the sun_mc and the cloud_mc will centre into the cirlce for sun_mc
    package
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.events.Event;
    public class DragDrop extends MovieClip
      public var target:MovieClip;
      private var originalX:Number;
      private var originalY:Number;
      public function DragDrop()
       originalX = this.x;
       originalY = this.y;
       this.addEventListener(MouseEvent.MOUSE_DOWN, drag);
      private function drag(event:MouseEvent):void
       this.startDrag();
       this.parent.addChild(this);
       this.addEventListener(MouseEvent.MOUSE_UP, drop);
      private function drop(event:MouseEvent):void
       this.stopDrag();
       this.removeEventListener(MouseEvent.MOUSE_UP, drop);
      if(this.hitTestObject(target))
        this.x = 19;
        this.y = 152;
       else
        this.x = originalX;
        this.y = originalY;
    Any tips on how to learn about drag/droping many items onto different targets would be appreciated.

    I ran into the same issue 2 months ago. After Verizons Spotlight news letter was released saying OAN was in HD as part of the Extreme package I tried viewing it with no success.
    I spent over an hour with a tech who said my channel modules were not set up correctly so he fixed it.
    Still couldn't get the channel and instead of admitting that they had no clue what to do the response I recvieved was, "Sorry the channel is no longer available to you as part of Extreme."
    So they were saying the channel which according to the Spotlight newsletter that they released and the online channel lineup which listed it as part of Extreme changed while I was chatting with them.  LOL
    After that response they rushed me out of chat.
    I ended up downgrading back to preferred. I wasn't about to pay for channels they say I should have but don't. It's still listed on all channel lineup's (paper included) as part of Extreme too. It seems the Extreme package is full of channel issues for a lot of people (was my 2nd one...had an issue with Hallmark channels) so it's better to stick with preferred or go all the way to Ultimate in my opinion.

  • Translating AS2 into AS3

    Hi, I am trying to create a scrollbar for a movie using a
    tutorial I found online (
    http://www.flashkit.com/tutorials/Interactivity/Scrollin-Jake_Gel-683/index.php).
    My problem is that I am new and am having issues translating the
    AS2 script into AS3. Is there anyone who could help me translate
    this:
    onClipEvent (load) {
    diff_y = bound_box._height-scroller._height;
    bounds = bound_box.getBounds(this);
    top = bounds.yMin+(scroller._height/2);
    bottom = bounds.yMax-(scroller._height/2);
    function updateScrollbar () {
    content._y =
    -(((scroller._y-top)/diff_y)*(content._height-bound_box._height));
    onClipEvent (mouseDown) {
    if (scroller.hitTest(_root._xmouse, _root._ymouse)) {
    startDrag ("scroller", false, scroller._x, top, scroller._x,
    bottom);
    scrolling = true;
    // here we stop the drag and set scrolling to false
    onClipEvent (mouseUp) {
    stopDrag ();
    scrolling = false;
    onClipEvent (enterFrame) {
    if (scrolling) {
    updateScrollbar();

    you have a 4 enterframe loops running continually when they
    only need to run after a menu item has been clicked and can stop
    after all menu items have reached their final positions.
    and you need to compute the final positions for each menu
    item after one of them is clicked.
    you might do better to check for an as3 tutorial for an
    accordian menu. it's a bit more involved than you're thinking.

  • 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.

  • Problem with Tweens and HitTest

    Hi guys,
    I have a problem with by code generated Tweens and HitTest.
    But first of all the backgeround info. I have a couple of dots. They are generated from a single movieclip and differ in scale. The idea is, that the biggest one ist set to the middle position of the stage.
    The others are coming from the outer stage border and are moving towards the middle position. This is done by using the Tween class.
    What should happen is, that they stop exactly at the border of the dots which are already in the middle. In the beginning there is just the main, big dot which was manually positioned to the middle. When the first dot reached its position, the bounding box should include this new dot.
    I use the hitTestObjects method to stop the Tweeing.
    The problem is, that there is a 80% chance that the dots have gaps or overlapping each other. Any thoughts on that?
    Thanks for every reply!
    This is the hitTesting Code in the main class:
    public function hitTesting(e:Event):void{
                                  for(var i:int=0; i<dotArray.length;i++){
                                                      for(var j:int=i+1; j<dotArray.length;j++){
                                                                if(dotArray[i].hitTestObject(dotArray[j])==true){
                                                                          dotArray[i].stopTweening();
                                                                          dotArray[j].stopTweening();
    This is the code for a single Dot
    public function Dot(anchorArray:Array,randomX:int,randomY:int,scaleVal:Number,first:Boolean, delayVal:Number, lastElement:Boolean, values:Array) {
         this.x=randomX;
         this.y=randomY;
         this.scaleX=this.scaleY=scaleVal;
         this.valueName=values[0];
         this.countValue=values[1];
         this.gRanking=values[2]
         this.lastElement= lastElement;
         this.first=first;
          if(!first){
               this.xTween = new Tween(this, "x", None.easeNone, this.x, anchorArray[0], 20, false);
               this.yTween = new Tween(this, "y", None.easeNone, this.y, anchorArray[1], 20, false);
               this.xTween.start();
               this.yTween.start();
    public function stopTweening():void{
      if(!first){
          if(lastElement)
               parent.removeEventListener(Event.ENTER_FRAME, parent.hitTesting);
          xTween.stop();
          yTween.stop();

    Ok guys,
    found a solution. It seems to be, that the build in HitTest functionality is to inaccurate for my problem.
    I found a better implementation here.
    Tanks for reading.
    -alex

  • 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