Convert code to as3

Hello guys.
Could you help me to take this code to as3?
Thanks
on (press) {
    i = Number(i)+1;
    duplicateMovieClip("/circle", "circle" add i, i);
    setProperty("circle" add i, _x, getProperty("/mousexy", _x));
    setProperty("circle" add i, _y, getProperty("/mousexy", _y));

i created a CircleClass.as and put inside this code
package
    public class CircleClass
        public function CircleClass()
after that i put in .fla the code  you told me
stage.addEventListener(MouseEvent.MOUSE_DOWN,f);
function f(e:Event):void{
var circle_mc:CircleClass=new CircleClass();
addChild(circle_mc);
circle_mc.x=e.stageX;
circle_mc.y=e.stageY;
I got this error
TypeError: Error #1034: Type Coercion failed: cannot convert CircleClass@2ec2f31 to flash.display.DisplayObject.
    at movt_fla::MainTimeline/f()[movt_fla.MainTimeline::frame1:9]

Similar Messages

  • Dummy Guide needed for converting AS2 code into AS3

    I have to convert my existing AS2 code into AS3, but I might as well be reading chinese. I never even began to learn AS3, it was still fairly new at the time and the class ended before we had an opportunity to even touch on it. My major was not web design, it was the print side of design. I took an additional class, after I graduated, to learn web design and our teacher told us, basically, that we were designers, not coders so we won't be getting much into actionscripting, beyond the basics. At the time I was relieved, but looking back, I really wish we would have gotten more into it. Bottom line, I need to learn now.
    Is there ANYONE that can help me out? I will list my code below, buy I am way beyond lost any help that can be provided, I would be so grateful!!!!
    On the main timeline I have the basic..
    stop(); -- I found the AS3 version, but I don't know what I'm looking at. I get "not_yet_set.stop()" and there are are 8 options I can choose from. I just want the timeline to stop until I tell it where to go next. And what is "not_yet_set"
    Then I have my buttons, which are, basically...
    on (release) {
    gotoAndStop("Home");
    Or "gotoAndPlay("Whatever");"
    I also have buttons for scrolling...
    on (press) {
    play();
    on (release) {
    stop();
    AND
    on (press) {
    _root.AboutMe_Controller.gotoAndPlay(…
    on (release) {
    _root.AboutMe_Controller.gotoAndStop(…
    For the on(release) command, this is what I found as the AS3 version: not_set_yet.dispatchEvent()

    because that's really as1 code, you have steeper learning curve than going from as2 to as3.
    first, remove all code from objects, assign instance names to your buttons and you can then start on as3:
    // so, if you name your home button, home_btn:
    home_btn.addEventListener(MouseEvent.CLICK,homeF);
    function homeF(e:MouseEvent):void{
    gotoAndStop("Home");
    p.s.  the not_yet_set stuff is there because you tried to use script assist or some other actionscript shortcut.

  • Non video Seekbar code in as2. Can someone convert it to as3?

    Hi all,
    I am a newbie in Flash. Found a code from somewhere that is written to use seekbar to control the complete timeline in as2. Just need help from somone to convert it into as3.
    This code is placed in the slider button that is held to move forward or back the animation.
    on (press)
        dragging = 1;
        _parent._parent.stop();
        _parent._parent.ani.stop();
        _parent._parent.roll.ps.gotoAndStop(2);
    on (release, releaseOutside)
        dragging = 0;
        if (_parent._parent.st == 1)
            _parent._parent.roll.ps.gotoAndStop(1);
            _parent._parent.play();
            _parent._parent.ani.play();
        } // end if
    This function is placed in a symbol that contains a slider, named mcslider. It works perfectly in as2.
    function min(cfr)
        cframe = cfr;
        smod = cframe / 30;
        seco = Math.floor(smod);
        minut = seco / 60;
        minu = Math.floor(minut);
        if (minu < 10)
            minute = "0" + minu;
        else
            minute = minu;
        } // end else if
        return (minute);
    } // End of the function
    function sec(cfr)
        cframe = cfr;
        smod = cframe / 30;
        seco = Math.floor(smod);
        minut1 = seco % 60;
        minu1 = Math.floor(minut1);
        if (minu1 < 10)
            second = "0" + minu1;
        else
            second = minu1;
        } // end else if
        return (second);
    } // End of the function
    i = 0;
    seco = 0;
    m_e = 0;
    s_e = 0;
    minute = 0;
    second = 0;
    mtotal = 0;
    onEnterFrame = function ()
        total = _parent._totalframes;
        knob._x = _parent._currentframe * segmentWidth - segmentWidth;
        cfr = _parent._currentframe;
        s_e = sec(cfr);
        m_e = min(cfr);
        s_e1 = sec(cfr);
        m_e1 = min(cfr);

    var tl:MovieClip=this;
    tl.addEventListener(Event.ENTER_FRAME,enterframeF);
    paramF(tl,1,0,tl.totalFrames,slider.track.width);  // create a horizontal slider movieclip that contains a track movieclip and a thumbscroll movieclip that do the obvious and have left-sided reg point
    paramF(slider,0,1,slider.track.width-slider.thumbscroll.width,tl.totalFrames);
    var scrollRect:Rectangle=new Rectangle(0,0,slider.track.width-slider.thumbscroll.width,0);
    function enterframeF(e:Event):void{
    slider.thumbscroll.x=tl.m*tl.currentFrame+tl.b;
    slider.thumbscroll.addEventListener(MouseEvent.MOUSE_DOWN,scrolldownF);
    slider.thumbscroll.addEventListener(MouseEvent.MOUSE_UP,scrollupF);
    function scrolldownF(e:MouseEvent):void{
    tl.removeEventListener(Event.ENTER_FRAME,enterframeF);
    slider.thumbscroll.startDrag(false,scrollRect);
    slider.addEventListener(Event.ENTER_FRAME,scrollF);
    function scrollupF(e:MouseEvent):void{
    tl.addEventListener(Event.ENTER_FRAME,enterframeF);
    slider.thumbscroll.stopDrag();
    slider.removeEventListener(Event.ENTER_FRAME,scrollF);
    function scrollF(e:MouseEvent):void{
    tl.gotoAndStop(Math.round(slider.thumbscroll.x*slider.m+slider.b));
    function paramF(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number):void{
    mc.m=(y1-y2)/(x1-x2);
    mc.b=y2-mc.m*x2;

  • Please need help converting AS2 to AS3 code

    Hi, I want to convert an AS2 code to AS3. Someone can tell
    what is wrong. (it is about a speed effect) - Thanks a lot.
    mport flash.filters.BlurFilter;
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    var duration:Number = 15;
    var t1:Tween = new Tween(mcToTween1, "_x", Elastic.easeIn,
    133, 367, duration, 0);
    var t2:Tween = new Tween(mcToTween1, "blur", Elastic.easeIn,
    0, 0, 1, true);
    t1.onMotionChanged = function() {
    oldx = x;
    oldy = y;
    x = mcToTween1._x;
    y = mcToTween1._y;
    speedx = Math.round(Math.abs((x-oldx)));
    speedy = Math.round(Math.abs((y-oldy)));
    mcToTween1.filters = [new BlurFilter(speedx*2, speedy*2, 1)];
    trace(speedx);
    t1.onMotionFinished = function() {
    t1.yoyo();
    };

    use:
    MovieClip(parent.parent.parent).rdcmndPause=1;
    this.addEventListener(KeyboardEvent.KEY_DOWN,keydownF);
    function keydownF(e:KeyboardEvent):void{
    fscommand("KEYPRESSED", e.keyCode);
    if(e.keyCode==32){
    MovieClip(parent.parent.parent).rdcmndNextSlide=1;

  • Help plsss converting this AS2 code to AS3!!

    here is a little AS2 code that is in fact a photo gallery
    that i use in my site and i want to convert it to AS3 but i just
    cant seem to get it right... could someone plssss help me?!?!

    with what part are you having trouble?

  • Need assistance converting some AS2 code to AS3

    Hi,
    I have some simple AS2 code that brings in a MovieClip when
    you click a button. This is currently AS2, and I would rather
    convert it to AS3. I also have some code which closes the MovieClip
    upon button Click.
    The code I am currently using is below:

    addMC is the name of one of the event handler functions, not
    the button(s). the button instance names are: addButton and
    removeButton.
    To have three of them, duplicate what you see and have new
    variables, functions, and button names for all three sets, adjusted
    appropriately.
    I'm pretty sure this isn't over yet, I'm just giving you code
    per your defined scenario, which may have a hole or two in it. Try
    it out and see what you really want to do, then come back when you
    find out things need to be tamed in some way or aren't working as
    you want. There are more complicated ways to deal with a situation
    depending on what you really want, and I'm one who prefers to see
    some work done at your end that shows you've tried something (I'm
    not mean, much, I just have this thing about learning by doing).

  • Trying to convert AS2 code to AS3

    I had this code in AS2 and it worked I am trying to convert
    it to AS3 however and am stuck Please Help!!
    Thanks,
    Alex

    just add your click listeners and handlers:

  • Help! Convert simple Flash AS2 code to AS3

    Hi everyone,
    I'm a Flash beginner and followed a tutorial: http://www.webwasp.co.uk/tutorials/018/tutorial.php ... to learn how to make a "live paint/draw" effect. I didn't realize  that if I made something in AS2, I wouldn't be able to embed it (and  have it work) into my root AS3 file, where I've got a bunch of other  stuff going on. I've tried following tips on how to change AS2 code to  AS3, but it just doesn't work. I know it's simple code, and that some  genius out there can figure it out, but I'm at a loss. Please help!
    Here's the AS2 code:
    _root.createEmptyMovieClip("myLine", 0);
    _root.onMouseDown = function() {
       myLine.moveTo(_xmouse, _ymouse);
       ranWidth = Math.round((Math.random() * 10)+2);
       myLine.lineStyle(ranWidth, 0xff0000, 100);
       _root.onMouseMove = function() {
          myLine.lineTo(_xmouse, _ymouse);
    _root.onMouseUp = function() {
       _root.onMouseMove = noLine;
    Thanks in advance!
    Signed,
    Nicolle
    Flash Desperado

    Considering the code is on timeline:
    var myLine:Sprite = new Sprite();
    addChild(myLine);
    var g:Graphics = myLine.graphics;
    addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    function onMouseDown(e:MouseEvent):void {
         var ranWidth:Number = Math.round((Math.random() * 10) + 2);
         g.clear();
         g.lineStyle(ranWidth, 0xFF0000, 1);
         addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
         addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    function onMouseMove(e:MouseEvent):void {
         g.lineTo(mouseX, mouseY);
    function onMouseUp(e:MouseEvent):void {
         removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
         removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);

  • Checking convert from AS2 - AS3

    I am praticing to convert AS2 to AS3 code . Here moviclip instance name is handle_mc. Here I have AS2 code and trying to convert into AS3. Will u please look at my code of AS3. Is my code is correct ?
    AS2 Code 
    stop();
        var t1:Number = 0;
        handle_mc.onPress = function() {
            if (t1>=0) {
                if ((getTimer()-t1)<300) {
                    popContent_mc.play();
                } else {
                    _root.main.pop_mc.startDrag();
            } else {
                t1 = 0;
            var time:Number = getTimer();
            t1 = time;
        handle_mc.onRelease = function() {
            _root.main.pop_mc.stopDrag();
    AS3 Code
    stop();
        var t1:Number = 0;
        function press_handle_mc(event:KeyEvent)
            if (t1>=0) {
                if ((getTimer()-t1)<300) {
                    popContent_mc.play();
                } else {
                    _root.main.pop_mc.startDrag();
            } else {
                t1 = 0;
            var time:Number = getTimer();
            t1 = time;
        function click_handle_mc(event,MouseEvent)
            root.main.pop_mc.stopDrag();
        handle_mc.addEventListener(KeyEvent.PRESS,press_handle_mc);
        handle_mc.addEventListener(MouseEvent.CLICK,click_handle_mc;

    No, you still have AS2 code elements in your AS3 code.  If you really are trying to learn this, and not just seeing if you can get people to do your design work for you, then you should be running the code, seeing what errors occur, and then researching how to fix them one at a time.  The compiler will be happy to tell you where you have problems.  That is how you will learn it.

  • As2 code to As3 conversion please

    Hey, could someone help me converting the following code to AS3. Thanks for any help..
    id=_root.id;
    if(this._y<>_root.txk){
    this._y=_root.txk;
    _root.txk+=60;
    this._x=_root.txx;
    textyazı="";
    onEnterFrame=function(){
    this._name=namet.text;
    if(_root.txk==360){
    _root.txx+=60;
    _root.txk=60;
    this.onPress=function(){
    if(_root["t"+namet.text].txtn.text<>namet.text){
    _root.attachMovie("txt_dd","t"+namet.text,_root.derinlik);
    _root["t"+namet.text]._x=100;
    _root["t"+namet.text]._y=100;
    _root["t"+namet.text].txtyname.text=namet.text;
    _root["t"+namet.text].txtn.text=namet.text;
    _root["t"+namet.text].txtyazılar.text=textyazı;
    _root.derinlik++;
    txtac = SharedObject.getLocal(id);
    setInterval(function(){
    if(txtac.data.namet<>"" && txtac.data.id>0){
    namet.text=txtac.data.namet;
    textyazı=txtac.data.textyazı;
    id=txtac.data.id;
    }else{
    namet.text=_name;
    if(namet.text=="undefined"){
              namet.text=_name;
    if(textyazı==undefined){
              textyazı="";
    },50);
    this.useHandCursor=false;

    1.download flashdevelop (Flash has bad code hinting and error descriptions)
    2.start with deleting underscores in _root,_x,_y
    3.work your way up from there
    4.Lines like:
    this.onPress=function
    are probably attached directly to a button or MovieClip: This is not possible in as3 anymore. You have to take the code out of the button and put it on the timeline of the button, if it is a MovieClip.
    5.The Event Model has changed considerably:
    onEnterFrame=function(){
    // do stuff here
    is now
    addEventListener(ENTER_FRAME, enterFrameHandler);
    function enterFrameHandler(e:Event):void{
    //do stuff here

  • How to convert AS2 to AS3

    Hi I am new to flash AS3. I have a program in AS2 and wants to convert it in AS3. I change the settings from File->Publish Settings. and selected "Flash player 9 and Action Script 3" and after that I am getting some error message and WARNING
    WARNING: Actions on button or MovieClip instances are not supported in ActionScript 3.0. All scripts on object instances will be ignored.
    WARNING: Text field variable names are not supported in ActionScript 3.0. The variable 'NumResults' used for an unnamed text field will not be exported.
    Please suggest me how do I resolve this WARNINGs.

    You are likely to find those are just a few top level errors/warnings you'll get when you try to turn an AS2 file directly into an AS3 file.  There's probably a long line of others regarding syntax and properties that will pop up once you start trying to compile the file.
    AS3 does not allow code to be attached to objects like earlier versions of AS did, so you need to find each object (usually buttons) that has code attached to it, give instance names to those objects, and create that code as event listener/handler pairs.
    AS3 does not allow textfields to carry vars as identifiers, so again you need to assign instance names to the textfields and use the "text" property to assign or read String values to/from them.  So if you have variables that relate to textfield values, then those variables have to be equated to the text property of the textfields... var textVar = text_field.text   OR  text_field.text = textVar

  • Changing Code Into AS3

    I have a code that I wrote in AS2 and I am now trying to
    convert it into AS3 . . . When I converted it this is what I came
    up with but I can still not get it to work.
    Can someone help me fix it? I used a coverter for some of it
    http://www.5etdemi.com/convert/index.php
    . . . does anyone know of a better one?
    Thanks for any help fixing the code

    :

  • Help Converting AS2 to AS3 Drag and Drop Event

    Hi All,
    This is the second post on help for converting AS2 to AS3. This code is used in Captivate to allow a drag and drop action between two areas (User presses down, drags, and releases in a second area - They are not dragging any object). If anyone can help me convert this please let me know.
    Source for Drag and Drop: (Note: Single MovieClip)
    // pause the Captivate movie
    _root.rdcmndPause = 1;
    // when the user's mouse is let go check if there was a successful drop
    _root.onMouseUp = function(){
              // If the source area's center coordinate is nearby the destination area's center coordinate then advance the slide
              if ( Math.abs(_root.sourceX + _root.sourceWidth  / 2 + _root.sourceParentX - (_root.destX + _root.destWidth  / 2)) < (_root.destWidth  / 2) &&
                         Math.abs(_root.sourceY + _root.sourceHeight / 2 + _root.sourceParentY - (_root.destY + _root.destHeight / 2)) < (_root.destHeight / 2) )
                        _root.rdcmndNextSlide = 1;
              } else {
                        // show error movie clip for 2 seconds (60 frames at 30 frames per second)
                        _root.showErrorMessage = 60;
      mc.onEnterFrame = function(){
              // continuously update the source area's coordinates and size
              _root.sourceX = mc._x;
              _root.sourceY = mc._y;
              _root.sourceWidth = mc._width;
              _root.sourceHeight = mc._height;
              _root.sourceParentX = _parent._x;
              _root.sourceParentY = _parent._y;
    mc.onPress = function(){
              // Uncomment following line to have control click capabilities
              //if(key.isDown(Key.CONTROL))
              // when user clicks on the source area click start the drag
                        startDrag(this);
    mc.onRelease = function(){
              // stop drag when user releases the source area
              stopDrag();
    Source for Destination Area (Single MovieClip named destArea)
    // Set a root variable to control when the error message is displayed
    _root.showErrorMessage = -1;
    // Use setCoords variable so we only set the destination coordinates once
    var setCoords = 0;
    destArea.onEnterFrame = function(){
              if (setCoords == 0){
                        // set the destination x, y, width, and height
                        _root.destX = _parent._x;
                        _root.destY = _parent._y;
                        _root.destWidth = _parent._width;
                        _root.destHeight = _parent._height;
              // destination coordinates have been set, change setCoords so it doesn't get set again
              setCoords = 1;
    Code for the Error Message (Single MovieClip named errorMessage)
    // Don't display the error message initially
    errorMessage._alpha = 0;
    errorMessage.onEnterFrame = function (){
              // If the drag and drop method detects a missed drop
              // then show this error message by setting _alpha to 100
              if (_root.showErrorMessage > 0){
                        errorMessage._alpha = 100;
                        // decrementing this variable controls the time the
                        // error message will be displayed
                        _root.showErrorMessage--;
              } else {
                        // Don't display the error message
                        errorMessage._alpha = 0;

    use:
    MovieClip(parent.parent.parent).rdcmndPause=1;
    this.addEventListener(KeyboardEvent.KEY_DOWN,keydownF);
    function keydownF(e:KeyboardEvent):void{
    fscommand("KEYPRESSED", e.keyCode);
    if(e.keyCode==32){
    MovieClip(parent.parent.parent).rdcmndNextSlide=1;

  • Converting AS2 to AS3 Please!

    Hi guys.
    I having a major problem in trying to convert an old AS2 code into AS3.
    It would be great if you guys could help in anyway you can.
    onClipEvent (enterFrame)
        this;
        if (_x > 520)
            setProperty(this, _x, -20);
        } // end if
        this;
        if (_x < -20)
            setProperty(this, _x, 520);
        } // end if
        setProperty(this, _x, _x + Number(1.250000E+000));

    In the timeline of the object in question, try:
    addEventListener(Event.ENTER_FRAME, moveX);
    function moveX(evt:Event):void {
        if(x > 520){
             x = -20;
        if(x < -20){
             x = 520;
        x += 1.25;

  • Migrate existing code of AS3 to AS2 - URLRequest, URLLoader

    Hi,
    I have written code to read an XML file by using URLRequest and URLLoader in ActionScript 3.0. Code is pasted below. This runs well in AS3.  Problem I am facing is because I wrote this in AS3, I am not able to use the DateChooser component in another part of the flash module because it seems like DateChooser component is not supported in AS3. So I want to migrate my below AS3 code back to AS2.
    **** Code in AS3 (I need help in writing equivalent code in AS2) :-
    var xmlText:XML ;
    var xmlReq:URLRequest = new URLRequest("myFile.xml");
    var xmlLoader:URLLoader = new URLLoader();
    xmlLoader.load(xmlReq);
    xmlLoader.addEventListener(Event.COMPLETE,xmlLoaded);
    function xmlLoaded(event:Event):void
        xmlText = new XML(xmlLoader.data);  
        info_txt.htmlText = xmlText.someTag ;
    **** I cannot use the above as is because, when I change the publish settings from AS3 to AS2, I get following errors -
    The class or interface 'URLRequest' could not be loaded.
    The class or interface 'URLLoader' could not be loaded.
    The class or interface 'Event' could not be loaded.
    Same works well in AS3. What should I do to make this work in AS2 or can anyone direct me in writing an equivalent in AS2.
    Please assist.
    Thanks in advance.
    MG

    parsing is done using the xmlnode methods and properties.  how you parse an xml file (in as2) depends on its structure.  but generally, you use firstChild, nextSibling, childNodes and nodeValue in the appropriate sequence to extact data.  the flash help files have sample code.  for tutorials, check google.
    if you're trying to load a cross-domain xml file, you'll have a cross-domain security issue to deal with.

Maybe you are looking for