A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: How can I change this code from AS2 to AS3?

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    3

    Unhappy How can I change this code from AS2 to AS3?

    Hey there, I've got a problem that I'm working on a project & its programming is written in AS3. All I want is to convert this code for AS3 cuz I'm not very much familiar with it.

    Code:
    onClipEvent(load){
        normalX = this._x;
        normalY = this._y;
    }
    onClipEvent(enterFrame){
        this._x = normalX+(_root._xmouse/20);
        this._y = normalY+(_root._ymouse/20);
    }
    Thanks

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The event architecture of AS3 has been unified and made more powerful. Instead of onClipEvent code sections, you use addEventListener to associate a listener function with an event type.

    There is no load event anymore (there is a COMPLETE event that is dispatched when you load something with a Loader, but I don't think you're doing that). Perhaps you want to put that code in the class constructor, or in a listener for Event.ADDED_TO_STAGE, or even just on the first frame.

    Code:
    var normalX:Number = x;
    var normalY:Number = y;
    
    addEventListener(Event.ENTER_FRAME, doFrame);
    
    function doFrame(e:Event):void{
      x = normalX + (root.mouseX/20);
      y = normalY + (root.mouseY/20);
    }
    You cannot place code in library symbols anymore, but you can still put it on the timeline of an individual instance. If you want code to apply to all instances of a symbol, you need to create a class and associate your symbol with that class.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center