Create object without instance name

hi
here is the problem , i have hero shoot bullets and because of that i cant give the objects an instance names and i wanna check if the object on the stage or not and that is easy when
i do    var bullet:BULLET = new BULLET
if (bullet.stage){
addChild(bullet)
but the problem that when i do like this
addChild(new BULLET())
i know that , flash give them a names but how can i check their names??
if(???.stage)
thank you

Per Ned's suggestion you should use some structure. Because it seems you will use animations of large numbers of objects - Vector is the best because it is faster than Array.
Here is an example in two iterations - first as timeline code (just paste it on timeline), and below - as document class - you can use it by placing it into the same directory as your fla and assign doc class to Shooter:
import flash.display.Sprite;
import flash.events.Event;
var bullets:Vector.<BULLET>;
init();
function init():void
    makeBullets();
    placeBullets();
    shoot();
function shoot():void
    addEventListener(Event.ENTER_FRAME, moveBullets);
function moveBullets(e:Event):void
    for each (var b:BULLET in bullets)
        b.x += 10;
function placeBullets():void
    var nextX:Number = 0;
    for each (var b:BULLET in bullets)
        addChild(b);
        b.y = stage.stageHeight * .5;
        b.x = nextX;
        nextX -= b.width * 2;
function makeBullets():void
    var numBullets:int = 500;
    bullets = new Vector.<BULLET>();
    while (numBullets--)
        bullets.push(new BULLET());
Class:
package
    import flash.display.Sprite;
    import flash.events.Event;
    public class Shooter extends Sprite
        private var bullets:Vector.<BULLET>;
        public function Shooter()
            init();
        private function init():void
            makeBullets();
            placeBullets();
            shoot();
        private function shoot():void
            addEventListener(Event.ENTER_FRAME, moveBullets);
        private function moveBullets(e:Event):void
            for each(var b:BULLET in bullets) {
                b.x += 10;
        private function placeBullets():void
            var nextX:Number = 0;
            for each(var b:BULLET in bullets) {
                addChild(b);
                b.y = stage.stageHeight * .5;
                b.x = nextX;
                nextX -= b.width * 2;
        private function makeBullets():void
            var numBullets:int = 500;
            bullets = new Vector.<BULLET>();
            while (numBullets--) {
                bullets.push(new BULLET());

Similar Messages

  • Hit testing without instance names

    I know its possible to hit test From something without an instance name if you have it in a seperate .as file. All you have to do is type in this.hitTest(InstanceName);
    But, Is it possible to do a hit test from something without an instance name against something else that dosent have an instance name?
    this.hitTest(Other);
    And if so is it possible to assign the other object to a variable?
    var Target:Obj;
    Target = this.hitTest(Other);
    these are just my theories as to what the code should look like, Can anyone confirm that its correct, deny that its possible, or show me how it should look? Thanks in advance.

    well, in the beggining of the program there wont even be any hit tests to do. but as the program goes on, later to have to do around 9-10 hit tests per second. as i know that its not what you do, but how many times you do it that slows up a computer, would this effect the programs performance at that rate?
    Date: Fri, 18 Jun 2010 15:27:06 -0600
    From: [email protected]
    To: [email protected]
    Subject: Hit testing without instance names
    if you spawn n objects, you have n*(n-1)/2 hittests to check.  that's the way it is unless you use a technique to decrease that work-load.  and techniques to do just that do exist.
    but in your situation it sounds like you have have 2 or 3 objects to check for hittests which means you only have 1 or 3 hittests to check.
    >

  • Is it posible to create objects with different names dinamically?

    Hi,
    I'm creating an app that manages different wireless nodes in a network and I was thinking that I could create a class called Node which would have a constructor that every time I created an object Node, I would pass the address and some other data about the Node and the constructor will save all that data and also create a unique ID for every Node object.
    Now the problem is that I need to be able to discover all the nodes in my network every time the user clicks a Ping button. So every time the users clicks Ping I need to do a ping and create as many Node objects as nodes I have in my network. The thing is I don't know how to make it create the node objects with different names so after I've created all the nodes objects I can refer to one of them.
    Something like this.
    int Id=0;
    id++;
    Node node+Id = new Node();
    I think its not possible to do something like that. If it isn't how can I do to refer to one of the objects I've created?
    Thanks.

    Twistx77 wrote:
    Thanks to both of you. I'll check out the Link and if I can't find the solution there I'll make the array , I don't know how I didn't think about doing that. There are two collections you should study specifically:
    First you have the ArrayList which in essense is a growable array. This means you don't have to decide in advance how big it can be.
    Second there's the HashMap. It's sometimes called an associate array. Such an array doesn't have fixed position indexes like an ordinary array. Instead each index (called key) is associated with a value but the keys don't have any particular order. Still, given a certain key, finding the corresponding value in a HashMap is almost as fast as an array access.

  • Creating Object without new operator?

    How to create an object without a new operator. ????????????
    reply soon?????

    georgemc wrote:
    !!!!!!!!!!!!!!!!!!!!!!!!Y???????!?!?!?!?!?!??!?!?!!?!o!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!u!!????????????????????????? ?????????????c!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!a!!!!!!!!!!?!??!??????????n???????????????!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!????????i??....>?!!!!!!!!!!!!!!!!!!!n!!!!!!!!!!!!!!!!!!!!!!????????????s!!!!!!!!!!!!!!!!!!!!!t????????????????a!!!!!!!!!!!!!!!!!!!!!!!!!!!!!??????????????????????
    n????????????????!!!!!!!!!!!!!!!t@~!~!@!(*!!i!!!!!!!!!!!!!!!!!!!!!a????????????????????t!!!!!!!!!!!!!!!!!!e??????????????
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!a"*"(&*^?(^"(^("n??????????????????????
    !!!!!!!!!!!!!!!!!!!!o??????????????,,,,,b*************&&"&"j!!!!!!!!!!!!!!e?????????????c!!!!!!!!!!!!!!!!!!!!t???????????
    !!"(&?(($"u??????????????????s!""""""""""""""i??????????????n???????????????g(*&*%**%*(
    )(*&($[][]!r????????????????e!!!!!!!!!!!!!!!!!!!!!f~~@~@~@~>?>>>l!!!!!!!!!!!!!!!!!e??????????????c"??(&^^(?(t?????????i!!!!
    ))))))))___o------_++(*^*&%*!!n,>>>>>>>>>>, ?????????????????b!!!!!!!!!!!!!!!!!y???????????? *%*^(%*^(c!!!!!!!!!!!!!!l??????????
    !!!!!!!!!!!!!!!!!!!!!!!!!!o""""????????????n)))&(*&)&)=i=============n!!!!!!!!!!!!!!!!g?????????
    ?")*&)(?&)&)?a?????????????????????n&&&&&&&&&&&&&& ??????????????e!!!!!!!!!!!!!!!!!!!!!!!!!x"""""""""""""""i??????????
    ?>?<>?(&?(s!!!!!!!!!!!!!!!!!!t?????????????????i&*******(^*(?n!!!!!!!!!!!!!!!!!g??????????? ?"?????!!!!o!!!!!!!!!!!!!!!!!!!!!!!!b?????????
    *&*^*^*%(%(%(j!!!!!!!!!!!!!!!!!e????????????????c!!!!!!!!!!!!!!!!!!!!!t!!!!!!!!!!!!!!!!!!!!!!!!! ???????????o!!!!!!!!!!!r!!!!!!!!!!!!!
    ??????????????????????b"$$&(?&)(?y????????????????????? )&)(?&)&$)?d????????????????e!!!!!!!!!!!!!!!!!!!!
    !!!!!!!!!!!!s?????????????????????e!!!!!!!!!!!!!!!!!!!!!!!?r"????*^?(i!!!!!!!!!!!!!!!!!!!!!a??????????????l!!!!!!!!!!!!!!!i"""""""""""""""""""""""""""""""""""
    ?????????????z!!!!!!!!!!!!!!!!!!!i??????????n!!!!!!!!!!!!!!!!!!!!!!!g&&&&&&&&&&&&&& ?")*&?)&)"&)"s!!!!!!!!!!o?????????
    !!!!!!!!!&"!!!!!!!!!!e!!!!!!!!!!!!!!!!!!t???????????????????h???????!!!!!!!i!!!!!!"?n??????????????g!!!!!!!!!!!!!!!!!!!
    There's a pretty complete answer. Isn't all that extraneous puncutation annoying, thoughWhat extraneous punctuation?

  • HitTest with as objects no instance names

    Im making a game and i need a code to make hitTetObject between two as objects no instances because it addChild because the two Objects are not on the stage and if hitTest object it remove 1 of the objects

    If objects are not on the stage 1 of them cannot be removed but if addChild they are so use getChildAt if as objects no instances

  • Having trouble with creating objects from instances created with ClassLoade

    Hi.
    I'm having a bit of trouble with casting an instance of an object from a custom ClassLoader. Don't worry - the code isn't for anything sinister - it's for one of those life simulation thingies, but I want to make it modular so people can write their own 'viruses' which compete for survival. You know the score.
    Anyway. I've got the beginnings of my main class, which seems to load the class data for all 'virus' classes in a folder called 'strains'. There is a abstract class called AbstractVirus which declares the method calls for how the viruses should behave and to get textual descriptions, etc. AbstractVirus is to be subclassed to create working virus classes and these are what my main class is trying to load instances of.
    Unfortuantely, I can't cast the instances into AbstractVirus objects. The error I've been getting is 'ClassCastException' which I presume is something to do with the fact that my ClassLoader and the Bootstrap ClassLoader aren't seeing eye-to-eye with the class types. Can anyone help? This line of programming is really new to me.
    My code for the main class is below:
    /* LifeSim.java */
    public class LifeSim {
      public LifeSim() {
        /* Get a list of all classes in the 'strains' directory and store non-
         * abstract classes in an array. */
        Class virusClasses[] = null;
        try {
          /* Get a reference to the file folder 'strains' and make sure I can read
           * from it. */
          java.io.File modulesFolder = new java.io.File("strains");
          if (!modulesFolder.isDirectory() || !modulesFolder.canRead()) {
         System.out.println("Failed to find accessible 'strains' folder");
         System.exit(-1);
          /* Get a list of all the class files in the folder. */
          String virusFiles[] = modulesFolder.list(new ClassFileFilter());
          if (virusFiles.length == 0) {
         System.out.println("No virus strains in 'strains' folder");
         System.exit(-1);
          /* Create an array of class objects to store my Virus classes. Ignore the
           * abstract class as I cannot instantiate objects directly from it.*/
          virusClasses = new Class[virusFiles.length];
          VirusClassLoader classLoader = new VirusClassLoader();
          int j = 0;
          for (int i = 0; i < virusFiles.length; i++) {
         String virusName = "strains/" + virusFiles;
         Class tempClass = classLoader.loadClass(virusName);
         if (tempClass.getName().compareToIgnoreCase("strains.AbstractVirus") != 0) {
         virusClasses[j++] = tempClass;
    } catch (ClassNotFoundException ncfe) {
    System.out.println("Failed to access virus class files.");
    ncfe.printStackTrace();
    System.exit(-1);
    /* TEST CODE: Create an instance of the first virus and print its class
    * name and print details taken from methods defined in the AbstractVirus
    * class. */
    if (virusClasses.length > 0) {
    try {
         // Print the class name
         System.out.println(virusClasses[0].getName());
         Object o = virusClasses[0].newInstance();
         strains.AbstractVirus av = (strains.AbstractVirus) o;
         // Print the virus name and it's description
         System.out.println(av.getQualifiedName());
         System.out.println(av.getDescription());
    } catch (InstantiationException ie) { ie.printStackTrace(); }
         catch (IllegalAccessException iae) { iae.printStackTrace(); }
    public static void main(String args[]) {
    new LifeSim();
    class ClassFileFilter implements java.io.FilenameFilter {
    public boolean accept(java.io.File fileFolder, String fileName) {
    if (_fileName.indexOf(".class") > 0) return true;
    return false;
    class VirusClassLoader extends ClassLoader {
    private String legalClassName = null;
    public VirusClassLoader() {
    super(VirusClassLoader.class.getClassLoader());
    public byte[] findClassData(String filename) {
    try {
    java.io.File sourcefile = new java.io.File(filename);
    legalClassName = "strains." + sourcefile.getName().substring(0,sourcefile.getName().indexOf("."));
    java.io.FileInputStream fis = new java.io.FileInputStream(sourcefile);
    byte classbytes[] = new byte[fis.available()];
    fis.read(classbytes);
    fis.close();
    return classbytes;
    } catch (java.io.IOException ioex) {
    return null;
    public Class findClass(String classname) throws ClassNotFoundException {
    byte classbytes[] = findClassData(classname);
    if (classbytes == null) throw new ClassNotFoundException();
    else {
    return defineClass(legalClassName, classbytes, 0, classbytes.length);
    Thank you in advance
    Morgan

    Two things:
    I think your custom ClassLoader isn't delegating. In general a ClassLoader should begin by asking it's parent ClassLoader to get a class, and only if the parent loader fails get it itself. AFAIKS you could do what you're trying to do more easilly with URLClassLoader.
    Second, beware that a java source file can, and often does, generate more than one class file. Ignore any class files whose names contain a $ character. It's possible you are loading an internal class which doesn't extend your abstract class.

  • Creating Objects with String name

    How can i create an object, but just having the name as String?
    Like, instead of creating like JInternalFrame obj = new MyInternalFrame(), do it like JInternalFrame obj = createObject("MyInternalFrame") ( i just gave createObject as example, ignore it)...
    Does anyone knows how to do it? Because i have several windows, and by clicking, i dont want to be with a lot of if clauses checking each one to se wich one is the ritgh class to call...
    Tks,
    Bruno

    You need the Class class in package java.lang, specifically class (static) method forName() and instance method newInstance():
    JInternalFrame obj =
        (JInternalFrame) Class.forName("MyInternalFrame").newInstance();

  • Create object reference by name

    I wish to disable and enable a bunch of controls on the front panel. Instead of creating hard-wired property nodes, I wish to cycle through an array of string names of controls and set the corresponding control's property. Is it possible to create a reference on the fly based on a string? The reference will then be fed to a Property node. Or is there an alternative way for my problem?

    See the image below for a better example.
    This one provides a list of all the controls on the front panel.  See the names of the labels appears in the ArrayofCtrls.
    RayR
    You can create a subvi of this. Replace ThisVI by a control.  You then wire This VI from the calling VI.  Or, you can get fancy and wire a pathname to the appropriate function which replaces ThisVI in the above example.  You can then obtain front panel listings for other VI's.  The possibilities are alomost endless  
    Message Edited by JoeLabView on 01-08-2008 08:11 AM
    Attachments:
    _example.PNG ‏33 KB

  • Avery Template 74549 Is Not In Publisher Or Word.  How Can I Create These Without The Names Being Cut Off The Magins & Printable Areas?

    Publisher Dose Not Have Template For Name Badges As It Says It Should.  Template 74549 Wont Show & My Names R Not Properly Fit To The Squares
    ..  Please Help Me Get The Correct Template !!!

    This is a forum for Adobe InDesign questions. Perhaps there's a Publisher forum you can visit.
    Try Googling for it.

  • Unique instance names in distributed environment

    The 11.1.2.1 installation guide (http://download.oracle.com/docs/cd/E17236_01/epm.1112/epm_install_11121.pdf) says, on page 122 of the .pdf:
    +"When you configure in a distributed environment, provide a new, unique instance name as you configure each server. For example, if you are using the default instance name epmsystem1 on the first server, and you keep the same naming convention on subsequent servers, you would create new, unique instance names on each subsequent server, such as epmsystem2, epmsystem3, and so on."+
    No reason not to follow this advice, but wondering if it's really necessary. I feel sure I've seen installations where 'epmsystem1' was used on e.g. both a web application server and the Essbase server. Perhaps I'm remembering incorrectly.

    Yes each server requires a unique name as it is registers the server with the shared services registry against the instance name, maybe it was on a 11.1.2.0 deployment that you saw the same instance name across the distributed environment.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Provide a new, unique instance name - Distributed Environment

    Hi,
    I am not sure about this piece of information in installation docs
    please refer
    http://download.oracle.com/docs/cd/E17236_01/epm.1112/epm_install_11121/frameset.htm?launch.html
    When you configure in a distributed environment, provide a new, unique instance name as you configure each server. For example, if you are using the default instance name epmsystem1 on the first server, and you keep the same naming convention on subsequent servers, you would create new, unique instance names on each subsequent server, such as epmsystem2, epmsystem3, and >so on. What if i use same path "d:\.......\epmsystem1" on all servers in distributed environment?
    Regards
    Kumar
    Edited by: Kumar 1 on Oct 4, 2011 6:18 AM

    Thanks John,
    Mostly i configured different instance name ("D:\oracle\middleware\epmsystem1" and "D:\oracle\middleware\epmsystem2" etc.
    but i have one client where i see similar instance on all servers in distributed environment "D:\oracle\middleware\epmsystem1" and "D:\oracle\middleware\epmsystem1" etc.
    Please advice? and let me know what could be impact of these two scenario.
    Regards
    Kumar

  • Loading SWF giving Instance name as TimeLine

    I'm Loading swf into a movieclip name main_mc. After
    successfully loading it into main_mc. I had written a function to
    get all children present in that movieclip(main_mc). It is getting
    Children present in that, but every time it give [Object
    MainTimeLine] as instance3 or sometime instance10. How can i
    control instance name of maintimeline as it is randomly getting its
    name.... I'm attaching code use in getting child and loading it...
    Plz check if their any problem in code.
    quote:
    Clip=new Loader();
    var urlRequest:URLRequest=new URLRequest("test.swf");
    Clip.contentLoaderInfo.addEventListener(Event.COMPLETE,LoadingDone);
    Clip.load(urlRequest);
    private function LoadingDone(event:Event):void {
    var _mc:MovieClip=event.target.content as MovieClip;
    main_mc.addChildAt(_mc,0);
    //if i trace the name of _mc movieclip... it will instance4
    or instance10 randomly
    trace(_mc.name);
    showChildren(stage,0);
    function showChildren(dispObj, indentLevel:Number):void {
    for (var i:uint = 0; i < dispObj.numChildren; i++) {
    var obj:DisplayObject = dispObj.getChildAt(i);
    if (obj is DisplayObjectContainer) {
    trace(padIndent(indentLevel), obj.name, obj);
    showChildren(obj, indentLevel + 1);
    } else {
    trace(padIndent(indentLevel) + obj);
    function padIndent(indents:int):String {
    var indent:String = "";
    for (var i:uint = 0; i < indents; i++) {
    indent += " ";
    return indent;
    when loading is done suppose test.swf has one_mc movieclip
    Children traced are like that...
    quote:
    main_mc [object MovieClip]
    instance3 [object MainTimeline]
    one_mc [object MovieClip]
    [object Shape]
    Can we solve this problem...

    you can't control the instance name of a main timeline. but
    if you name everything else, the main timeline will be the only
    object whose instance name starts with "instance".

  • Using and storing instance names

    I know you can store instance names in an array and call on the array values to reference the instance names in it.
    I was wondering if there is any way I can take an instance name, feed it directly into a function and use the name of the function variable/array/whatever to affect the object instance of whatever I name.
    if it's an array of instance names, what is it actually an array of?
    Also, is there any way to hold and reference an instance name in a single value?
    sidenote:
    this doesnt have much to do with my question, but can arrays be fed directly into the header of a function?

    Look, there is no any ambiguity in what array holds - it is what you make it hold.
    If you are talking about instance names as strings, the following can be done (given objects with instance names are instantiated);
    var myInstanses:Array = ["instance1", "anotherInstance", "myMovie"];
    than you can feed instance name onto a function and do whatever you need to:
    function myFunction(instanceName:String):void{
         this[instanceName].x = 200;
    myFunction(myInstances[1]);
    But if you are talking about instances as instances - not names:
    var myInstanses:Array = [instance1, anotherInstance, myMovie];
    function myFunction(instance:Sprite):void{
         instance.x = 200;
    myFunction(myInstances[1]);

  • Creating dynamic object instance names

    If I have a class such as ...
    class NewDevice
    I would create a new instance of that object by calling 'NewDevice' as ....
    NewDevice nd = new NewDevice();
    Suppose I don't actually know how many device I need before I read a file in and then subsequently create a new object instance. I could have a long list of variable name i.e. nd1, nd2, nd3 etc but that would be messy and I would be sure to run out.
    My Question..........
    How do I create object instances with unique names 'on-the-fly' so to speak
    Thanks

    Here's an example that allows you to build up a list of NewDevice instances, see how many there are and get them back by their index in the list:
    public class MyClass
      List newDeviceList;
      public MyClass()
        newDeviceList = new ArrayList();
      public void addNewDevice(NewDevice newDevice)
        newDeviceList.add(newDevice);
      public int getNewDeviceCount()
        return newDeviceList.size();
      public NewDevice getNewDevice(int idx)
        return (NewDevice)newDeviceList.get(idx);
    }Hope this helps.

  • Schedule Webi (and Crystal) report without creating a new instance

    Hi all,
    I'm looking for the way to not create a new instance of the report when we schedule a report? Is it any actions on the InfoObject object? Or is it just impossible to do?
    Thanks in advance !
    Edited by: jerome.vervier on Nov 21, 2011 11:40 AM

    Hi,
    With regards to your query, whenever a report is scheduled an instance of it will be created.
    Therefore, it is not possible to schedule a report without creating an instance.
    Regards,
    Shreyans

Maybe you are looking for

  • Iphone recordings not playing on ipod

    Clips recorded on an iphone (m4a) will play in itunes, but not all will play on my ipod.  Do they need to be converted to another format?

  • Cannot make .war file using tomcat with eclipse and ant

    i have made all necesary configuration for deploying application using eclipse and ant for the tomcat server. when i start the server by clicking the tomcat icon on eclipse toolbar, the message is prompted that "missing application web.xml and using

  • Accrual

    hi gurus,                  what is accrual....what is the effect of this if i dont take it in pricing procedure and whats is the effect if i take it into account? any valuation changes? usually it is applied to freight condition types. can anybody br

  • Lenovo Twist S230U Integrated Camera not detected

    OS: Windows 8.1 x64 Camera apps says: To get started, connect a camera Device Manager does not show any missing device drivers or errors Attempting to install camera drivers I get the error: " Cannot find the device, abort install" Downloaded the dri

  • Editing the iTunes genre.plist???

    Hello, I have asked this question before in these forums, but I cannot locate it. I have edit the "genre.plist" to included some new music and movie genres. This reverts back to the original everytime I update iTunes. I have (or at least had) the fil