creating an array of movieclips in AS2 OOP

Long proceedural timer trying to pass to the OBJECT-oriented programming. Using the book "Object Oriented Actionscript for Flash 8" I created the example of a class with a movieclip that is passed as a parameter. Attempting to expand in an array of clips/classes and without success.

Here's the class:

-----------------
location class extends MovieClip {}

var targetMC:MovieClip;
var x: Number;
var y: Number;

function {location (x: Number, y: Number, targetMC:MovieClip)}
this.targetMC = targetMC;
This.x = x;
This.y = y;
moveTo(x,y);
}

function moveTo (x: Number, y: Number) {}
this.targetMC._x = x;
this.targetMC._y = y;
}

}
---------------------------
and for a single clip the following work in the fla

//----------------------------------------------------------
attachMovie ("dot", "dot", 1.1, 100);
var myLocation:Location = new location (dot, 200 300);
//-------------------------------------------

However when I try to create a table of 'points' it does not work.

//-----------------------------------------
var myLocation:Array = new Array();
for (x = 0; x < 5; x ++) {}
attachMovie ("dot", "dot" + x, 1, 1, 100 + x);
var myLocation [x]: location = new location (_root ["dot" + x], 200, 100 + x * 30);
}
//---------------------------------------

Also how to avoid using _root in this?

Great, thank you. I thought it was associated with OOP and am happy that it was just As Basic.

Tags: Adobe Animate

Similar Questions

  • Create an array of MovieClips with a statement

    Hello
    I'm trying to create a matrix of MovieClips with a statement, but it does not work.
    The code is the following:

    var PicLoader:MovieClipLoader = new MovieClipLoader();

    function createMovieClips() {}
    var c:Number = 1;
    var Pic1:MovieClip = new MovieClip;
    var Pic2:MovieClip = new MovieClip;
    var Pic3:MovieClip = new MovieClip;
    var Pic4:MovieClip = new MovieClip;
    var Pic5:MovieClip = new MovieClip;
    var Pic6:MovieClip = new MovieClip;
    var Pic7:MovieClip = new MovieClip;
    var Pic8:MovieClip = new MovieClip;
    var Pic9:MovieClip = new MovieClip;
    var Pic10:MovieClip = new MovieClip;
    var Pic11:MovieClip = new MovieClip;
    var Pic12:MovieClip = new MovieClip;
    var Pic13:MovieClip = new MovieClip;
    var Pic14:MovieClip = new MovieClip;
    var Pic15:MovieClip = new MovieClip;
    var Pic16:MovieClip = new MovieClip;
    for (var i: Number = 1; i < = 4; i ++) {}
    for (var j: Number = 1; j < = 4; j ++) {}
    _root.createEmptyMovieClip (eval ("Peak" + c), _root.getNextHighestDepth ()); eval("PIC"_+_C)._x = i * 100; eval("PIC"_+_C)._y = j * 100;
    _root. PicLoader.loadClip ("' http://www.sages.hu/galeria/kepek/kep1.jpg ', eval ("_root."+ eval ("Peak"+ c)));
    c ++ ;
    }
    }
    }


    createMovieClips();

    What I've done wrong?

    It is quite a mess. Try:

  • Create an array of Boolean 1 d of reference Boolean table 1 d

    Hello

    Any suggestions on how to create an array of Boolean 1 d of reference Boolean table 1 d?

    Thank you for any ideas?

    You can wire the reference to a node value property and get the array of Boolean.

  • easy way to create an array of [1, 2,..., 4956]?

    Y at - it easy and lazy to create an array of [1, 2,..., 4956]?

    Hi Cashany,

    LabVIEW has polymorphic functions and offers several solutions for your task...

  • How to create an array of strings listing by program?

    How to create an array of strings listing by program? I'm trying to programmatically create an Enum containing a list of tests to run, based on the selection of the user.

    My code ranging from control on LAVA has a demo VI to convert an array of strings of an enum.

    Tone

  • How to create dynamic arrays parallel/side-by-side in Adobe cycle

    Is it possible to create dynamic arrays parallel/side-by-side in Adobe cycle?  If so, how?

    Given that the tables have different sizes, in that I am running wrapping issues with running adjustment of Western characters and characters from the pagination with checkpoint.  Any other ideas?

    In fact, I had tried this solution ("wrapping the tables in a subform of position and set to automatically adjust the height and allow page breaks"), but it did not work.  Something to do with nested subforms of position within a subform control flow etc.  So to make it work, I set the page to be a subform of position and the auto-hauteur value and allow page breaks and I unpacked the paintings while they were only 'wrapped up' of the page itself.

  • access a movieClip within a movieclip in as2

    I'm trying to make a

    The MovieClip that is nested inside a movieclip in As2:

    MovieClip1.movieClip2.movieClip3.gotoAndStop (2)

    MovieClip1, MovieClip2, MovieClip3 is the case of names.

    Your approach is correct.  Based on the change in spelling between the two lines show you, if you encounter a problem, that may be the cause.

  • Error in creating a dynamic array of movieclips

    I'm creating a portfolio of scrolling, but will have questions affecting movieclips in a table.

    I am loading xml with the info of the image.  Which works very well.

    I created an empty movieclip in my library called pane() and set to export for actionscript with a window class name.

    I run the code below and get:

    0
    TypeError: Error #1009: cannot access a property or method of a null object reference.
    at rotating_portfolio_fla::MainTimeline/completeXMLLoad()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

    I guess that's a failure to assign newClip to mainClipArray.  If I take the code table, it loads the first frame very well.

    Can you see my mistake?

    CODE:

    var myXML:XML;
    var xmlLoader:URLLoader = new URLLoader();
    var mainClipArray:Array;
    var count: int = 0;
    var myLoader:Loader = new Loader();

    xmlLoader.load (new URLRequest ("portfolio.xml"));

    xmlLoader.addEventListener (Event.COMPLETE, completeXMLLoad);

    function completeXMLLoad(e:Event):void {}
    myXML = XML (e.target.data);
    var len:int = myXML.portfolio.unit.length ();
    for (var i: int = 0; i < len; i ++) {}
    counter = i;
    trace (Counter);
    var newClip:MovieClip = new pane();
    mainClipArray [i] = newClip;
    trace ("newClip.width" + newClip.width);

    Load the small image
    var smallfilename = myXML.portfolio.unit [i].small.filename;
    trace (smallfilename);

    myLoader.load (new URLRequest (smallfilename));
    myLoader.contentLoaderInfo.addEventListener (Event.COMPLETE, completeClipLoad);

    function completeClipLoad(e:Event):void {}
    mainClipArray [counter] .addChild (myLoader);

    }

    mainClipArray [i] .x = 100;

    trace ("mainClipArray [i] .width" + mainClipArray [i] .width);
    }
    }

    you create this table, too:

    var myXML:XML;
    var xmlLoader:URLLoader = new URLLoader();
    var mainClipArray:Array = [];
    var count: int = 0;
    var myLoader:Loader = new Loader();

    xmlLoader.load (new URLRequest ("portfolio.xml"));

    xmlLoader.addEventListener (Event.COMPLETE, completeXMLLoad);

    function completeXMLLoad(e:Event):void {}
    myXML = XML (e.target.data);
    var len:int = myXML.portfolio.unit.length ();
    for (var i: int = 0; i
    counter = i;
    trace (Counter);
    var newClip:MovieClip = new pane();
    mainClipArray [i] = newClip;

    addChild (newClip);
    trace ("newClip.width" + newClip.width);
           
    Load the small image
    var smallfilename = myXML.portfolio.unit [i].small.filename;
    trace (smallfilename);
           


    myLoader.load (new URLRequest (smallfilename));
    myLoader.contentLoaderInfo.addEventListener (Event.COMPLETE, completeClipLoad);
           
    function completeClipLoad(e:Event):void {}
    mainClipArray [counter] .addChild (myLoader);
               
    }
           
    mainClipArray [i] .x = 100;
           
    trace ("mainClipArray [i] .width" + mainClipArray [i] .width);
    }
    }

  • An array of MovieClips. When I change the properties, it duplicates the item...

    Greetings,

    I will do my best to explain what is happening. I have the feeling that this has something to do with how I say things, but I'm a bit new with AS3 so please have patience.

    On my stage, I have a movie clip (mContainer). In the library, I have an another movieclip (mElement), which has been exported for actionScript as mElement.

    The first image, I have the following code:

    import flash.events.*;
    
    var mElem:Array = new Array();
    
    stage.addEventListener(Event.ENTER_FRAME, onEnterFrameEvt);
    stage.addEventListener(MouseEvent.CLICK, onMouseClickEvt);
    
    function onEnterFrameEvt(event:Event):void {
      for (var i:uint=0;i<10;i++) {        
           mElem[i] = new mElement();
           mElem[i].x = 15*i;
           mContainer.addChild(barArray[i]);              
      }           
       mElem[2].x = 300; // (1) For testing purposes only...
    }
    function onMouseClickEvt(event:MouseEvent):void {
         mElem[2].x = 400; // (2) For testing purposes only...
    }
    
    this.stop();
    

    When the script reaches (1), she correctly moves the movieClip to new x. However, when I click on the scene, and the event is generated, (2) creates a copy of the object on the stage... so, I find myself with a single object at x = 300 and the other at x = 400 when what I actually wanted was to move the object from one place to the other.

    Could enlighten me is it someone please on why it doesn't work as I hope?

    Thank you very much!

    What is happening is that your enterframe event is continually running and re-create these 10 objects at a fast enough pace.  You can see if you are implementing a value of investment there as well and that increment for each execution of the loop for.  If you use removeEventListener to the enterframe event after completing the first execution of the function that adds all the songs, your pieces should behave as expected (I think... "I guess I understand the problem).

    If the intention is not to continuous fire that work, you should remove the enterframe listener entirely and just retrieves the code for the function and runs it just a moment.

  • Create parameter array

    All,

    I finally finished a VI that accepts 4 Strings, 1 Bool and 3 floats and calls a STORED PROCEDURE ala MS - SQL 2005 database, with the same interface (the STORED procedure also accepts the same inputs).

    The purpose is just to store the values as a record in a table.

    I was finally able to get this all working, but when I save the VI and re - open, I lost all the settings in my initial parameter array that is an input required for the 'DB tools create parameter query' except the 0th parameter.

    I don't know how to get these persists...  I can go to the front and add them at design time, and they remain there and work perfectly during the execution, but if I close the VI (and save) and re - open, I lose them.

    Thank you!

    Dave Sell

    Go to the Edit menu and select "use current default values. Save the VI. And before you save the VI, get rid of this sequence structure. It does nothing except make the program harder to read. Data flow is to control the order of execution.

  • Problem creating an array of objects

    Hello

    I have a xml.

    I read of the elements by using the loop.

    I want to store string data in an array whose size is not fixed.

    I am currently using vectors for this. But by storing the first sting

    some sort of error occurs and no exception is caught.

    Code:

    Title vector;

    for (int s = 0; s< loop;="" s++)="">

    Node fstNode = nodeLst1.item (s);
                
    If (fstNode.getNodeType () == Node.ELEMENT_NODE) {}
              
    Element fstElmnt = fstNode (element);
    NodeList fstNmElmntLst = fstElmnt.getElementsByTagName ("title");
    Element fstNmElmnt = fstNmElmntLst.item (0) (element);
    NodeList fstNm = fstNmElmnt.getChildNodes ();
    System.out.println ("name:" + ((node) fstNm.item (0)) .getNodeValue ());
                  
    title.insertElementAt (((Node) fstNm.item (0)) .getNodeValue ()), s); ERROR GETTING PRODUCT HERE

    }
                 
    }
    }

    Any help?

    Thank you

    Afonso

    you declare the object without creating the instance of it.

    Use this

    Title vector = new Vector();

    I think that will be resolved.

    ------------------------------------------------------------------------------------
    Kudo press to say thank you to the developer.
    Also, press accept it as a button when you got the Solution.

  • Adjust the MovieClip with AS2 (hue) color?

    Hello

    I have a movieclip in my scene, I want to put a few buttons to change the hue of my clip to a specified number, is there any solution to make it!

    Thanks in advance

    var c:Color = new Color (yourmc);  Create an instance of color for yourmc

    c.setRGB (0xff0000);  assign 0xff0000 to color instance c of yourmc

  • Create an array of strings of names of JPEG in a folder

    I create a dynamic flash Gallery. I have filled external files with thumbnails, which are named descriptive. I was wondering if there was a way to create a string array of the names of JPEG (by file), then use that to drive my charger loop, instead of 'pic' + i + '.jpg', something like picArray [i], or picArray [i] + '.jpg '. I honestly don't want to rename hundreds of files named way descriptive pic1, pic2, etc., that I I want to use descriptive file name in the SWF file. In addition, if the user wants to browse the contents of the file without the SWF, they have an idea of what is the image. Any help is appreciated. Thanks in advance!

    lol you need to use a 3rd party (such as zinc) application or use another application like adobe air.

  • How to create an array of items from the loop.

    I have to get an array of elements obtained from the loop for so that I can use this table later in my program. When using range of table and cluster service arrayVI it gives only the last value generated in the loop. I want that all the values for each iteration to be stored in the table. Please suggest some options

    When a thread stops a loop, by default, it is automatically indexed in a table. Right-click on the tunnel and go back to that.

  • How can I create multidimensional arrays of controls?

    I build a VI that will have hundreds of power keys, 24 on each of the 8 tabs.  I can deal with them programmatically in an array, like this:

    and to find one that was pushed with some XOR'ing:

    But what happens if I want two rows of 12 buttons?  I can make a 2D buttons somehow?  Or a table 1 d of buttons on two lines for aesthetic reasons?

    What happens if I want to put 24 buttons on each of the 8 tabs?  Can I make a table of 24 x 8 controls somehow?  Or a 2 x 12 x 8?

    Thank you

    -Jordan

    Right click on the display of the Index and Add Dimension.

    I would be cautious to put too many buttons. Makes for an awkward interface.

Maybe you are looking for

  • Scan to E-mail feature does not

    Hello everyone! I had problems to set up the scan to email feature, the printer works fine print from the network, we did several tests, IP address works fine, it is static. I use as scanner email @.com, as scan, sender smtp.. com and port 25, no pin

  • Password protect only part of my block diagram

    Hello. Is it possible to protect only part of a diagram of bloack labview? I want people to use the VI and be able to make changes, but some parts (Sub VI) I already did and should not be changed. With greetings Espen

  • D110A series: scanning to PC

    Hello I am trying to scan from my printer Photosmart HP D110a scans my file and I get the following message is displayed: Error "Cannot perform the analysis because another program or computer using the networked HP imaging device." In the last three

  • How to "create a new folder on the hard drive?

    I have a printer Hp 648 with a W98 CD, that will not work for XP.  To download the XP driver on the HP site, the first step is to create as above.  Do not have any idea how I can do this and can't find anything in help.  Must be a folder that begins

  • How to return to preview of victory developer win7

    I have a hp laptop dv6-6195 this with me and it has a dedicated player called recovery. I installed win developer preview but I want to go back to my original windows 7, the main problem is that I have no disk recovery with me but I can see that my l