Setting the frame of an object based on collisions

I'm almost done with a project I've been working on for a while and need help with the Actionscript.  I first got help here: http://forums.adobe.com/message/4706107#4706107 ; basically what I set up was that an object would change its frame based on what other objects it was colliding with.  I'm working with hundreds of objects that will change based on their position onscreen so it's necessary to set up a script to do this automatically.  I don't know Actionscript at all, but I got a lot of help and we finally came up with this code:
stage.addEventListener(Event.ENTER_FRAME, checkForHit);
var objects:Array = new Array(obj, obj2);
function checkForHit():void {
     for(var i=0; i<objects.length; i++){
          for(var n=1; n<22; n++){
               if(objects[i].hitTestObject(this["invisibleObj"+String(n)]){
                     objects[i].gotoAndStop(n);
                     break;
The problem I'm running into now is that if an object specified in "new Array" isn't onscreen, none of the rest of the objects respond to the code.  Is there a way to make this code work regardless of whether all objects specified are onscreen or not?  Also, would there be a way to set the new Array objects to something like "obj*" so I didn't have to actually type in every single one of the hundreds of objects I'll be placing onscreen?
Thanks so much for the help!  I'm really stuck without it.

If you place all the objects in a container they will still be able to be hitTested with objects outside of the container.  If the objects are all passing by, then having them in the container might ease your burden since you could nove the container rather than each individual object.
To make the container just create an empty movieclip (or Sprite) symbol and place it on the stage at 0,0.  Open it up for editing and plant your 'object's as needed inside of it -  no names needed unless you have other need for them.  Then when you want to do your hitTesting you loop thru the children of the container.  Here's how the code changes if you do that and assign a name to that container of "objectContainer" (name it as you please)...
function checkForHit():void {
     for(var i=0; i<objectContainer.numChildren; i++){
        var obj:MovieClip = MovieClip(objectContainer.getChildAt(i));
          for(var n=1; n<22; n++){
               if(obj.hitTestObject(this["invisibleObj"+String(n)]){
                     obj.gotoAndStop(n);
                     break;

Similar Messages

  • How do I set the frame size

    I am Making a program for purchasing games, with the basic layout alsot done, except on problem. When the purchase button is pressed, a dialog shows up but nothing is seen until i resize it. How would i set the frame size so that i do not need to resize it each time? below is the code for the files. Many thanks in advance.
    CreditDialog
    import java.awt.*;
    import java.awt.event.*;
    class CreditDialog extends Dialog implements ActionListener { // Begin Class
         private Label creditLabel = new Label("Message space here",Label.RIGHT);
         private String creditMessage;
         private TextField remove = new TextField(20);
         private Button okButton = new Button("OK");
         public CreditDialog(Frame frameIn, String message) { // Begin Public
              super(frameIn); // call the constructor of dialog
              creditLabel.setText(message);
              add("North",creditLabel);
              add("Center",remove);
              add("South",okButton);
              okButton.addActionListener(this);
              setLocation(150,150); // set the location of the dialog box
              setVisible(true); // make the dialog box visible
         } // End Public
         public void actionPerformed(ActionEvent e) { // Begin actionPerformed
    //          dispose(); // close dialog box
         } // End actionPerformed
    } // End Class
    MobileGame
    import java.awt.*;
    import java.awt.event.*;
    class MobileGame extends Panel implements ActionListener { // Begin Class
         The Buttons, Labels, TextFields, TextArea 
         and Panels will be created first.         
         private int noOfGames;
    //     private GameList list;
         private Panel topPanel = new Panel();
         private Panel middlePanel = new Panel();
         private Panel bottomPanel = new Panel();
         private Label saleLabel = new Label ("Java Games For Sale",Label.RIGHT);
         private TextArea saleArea = new TextArea(7, 25);
         private Button addButton = new Button("Add to Basket");
         private TextField add = new TextField(3);
         private Label currentLabel = new Label ("Java Games For Sale",Label.RIGHT);
         private TextArea currentArea = new TextArea(3, 25);
         private Button removeButton = new Button("Remove from Basket");
         private TextField remove = new TextField(3);
         private Button purchaseButton = new Button("Purchase");
         private ObjectList gameList = new ObjectList(20);
         Frame parentFrame; //needed to associate with dialog
         All the above will be added to the interface 
         so that they are visible to the user.        
         public MobileGame (Frame frameIn) { // Begin Constructor
              parentFrame = frameIn;
              topPanel.add(saleLabel);
              topPanel.add(saleArea);
              topPanel.add(addButton);
              topPanel.add(add);
              middlePanel.add(currentLabel);
              middlePanel.add(currentArea);
              bottomPanel.add(removeButton);
              bottomPanel.add(remove);
              bottomPanel.add(purchaseButton);
              this.add("North", topPanel);
              this.add("Center", middlePanel);
              this.add("South", bottomPanel);
              addButton.addActionListener(this);
              removeButton.addActionListener(this);
              purchaseButton.addActionListener(this);
              The following line of code below is 
              needed inorder for the games to be  
              loaded into the SaleArea            
         } // End Constructor
         All the operations which will be performed are  
         going to be written below. This includes the    
         Add, Remove and Purchase.                       
         public void actionPerformed (ActionEvent e) { // Begin actionPerformed
         If the Add to Basket Button is pressed, a       
         suitable message will appear to say if the game 
         was successfully added or not. If not, an       
         ErrorDialog box will appear stateing the error. 
              if(e.getSource() == addButton) { // Begin Add to Basket
    //          GameFileHandler.readRecords(list);
                   try { // Begin Try
                        String gameEntered = add.getText();
                        if (gameEntered.length() == 0 ) {
                             new ErrorDialog (parentFrame,"Feild Blank");
                        } else if (Integer.parseInt(gameEntered)< 0
                                  || Integer.parseInt(gameEntered)>noOfGames) { // Begin Else If
                             new ErrorDialog (parentFrame,"Invalid Game Number");
                        } else { // Begin Else If
                             //ADD GAME
                        } // End Else
                   } catch (NumberFormatException num) { // Begin Catch
                        new ErrorDialog(parentFrame,"Please enter an Integer only");
                   } // End Catch
              } // End Add to Basket
         If the Remove From Basket Button is pressed, a  
         a suitable message will appear to say if the    
         removal was successful or not. If not, an       
         ErrorDialog box will appear stateing the error. 
         if(e.getSource() == removeButton) { // Begin Remove from Basket
              try { // Begin Try
                        String gameEntered = remove.getText();
                        if (gameEntered.length() == 0 ) {
                             new ErrorDialog (parentFrame,"Feild Blank");
                        } else if (Integer.parseInt(gameEntered)< 1
                                  || Integer.parseInt(gameEntered)>noOfGames) { // Begin Else If
                             new ErrorDialog (parentFrame,"Invalid Game Number");
                        } else { // Begin Else If
                             //ADD GAME CODE
                        } // End Else
                   } catch (NumberFormatException num) { // Begin Catch
                        new ErrorDialog(parentFrame,"Please enter an Integer only");
                   } // End Catch
              } // End Remove from Basket
         If the purchase button is pressed, the          
         following is executed. NOTE: nothing is done    
         when the ok button is pressed, the window       
         just closes.                                    
              if(e.getSource() == purchaseButton) { // Begin Purchase
                   String gameEntered = currentArea.getText();
                   if (gameEntered.length() == 0 ) {
                        new ErrorDialog (parentFrame,"Nothing to Purchase");
                   } else { // Begin Else If
                        new CreditDialog(parentFrame,"Cost � 00.00. Please enter Credit Card Number");
                   } // End Else               
              } // End Purchase
         } // End actionPerformed
    } // End Class
    RunMobileGame
    import java.awt.*;
    public class RunMobileGame { // Begin Class
         public static void main (String[] args) { // Begin Main
              EasyFrame frame = new EasyFrame();
              frame.setTitle("Game Purchase for 3G Mobile Phone");
              MobileGame purchase = new MobileGame(frame); //need frame for dialog
              frame.setSize(500,300); // sets frame size
              frame.setBackground(Color.lightGray); // sets frame colour
              frame.add(purchase); // adds frame
              frame.setVisible(true); // makes the frame visible
         } // End Main
    } // End Class
    EasyFrame
    import java.awt.*;
    import java.awt.event.*;
    public class EasyFrame extends Frame implements WindowListener {
    public EasyFrame()
    addWindowListener(this);
    public EasyFrame(String msg)
    super(msg);
    addWindowListener(this);
    public void windowClosing(WindowEvent e)
    dispose();
    public void windowDeactivated(WindowEvent e)
    public void windowActivated(WindowEvent e)
    public void windowDeiconified(WindowEvent e)
    public void windowIconified(WindowEvent e)
    public void windowClosed(WindowEvent e)
    System.exit(0);
    public void windowOpened(WindowEvent e)
    } // end EasyFrame class
    ObjectList
    class ObjectList
    private Object[] object ;
    private int total ;
    public ObjectList(int sizeIn)
    object = new Object[sizeIn];
    total = 0;
    public boolean add(Object objectIn)
    if(!isFull())
    object[total] = objectIn;
    total++;
    return true;
    else
    return false;
    public boolean isEmpty()
    if(total==0)
    return true;
    else
    return false;
    public boolean isFull()
    if(total==object.length)
    return true;
    else
    return false;
    public Object getObject(int i)
    return object[i-1];
    public int getTotal()
    return total;
    public boolean remove(int numberIn)
    // check that a valid index has been supplied
    if(numberIn >= 1 && numberIn <= total)
    {   // overwrite object by shifting following objects along
    for(int i = numberIn-1; i <= total-2; i++)
    object[i] = object[i+1];
    total--; // Decrement total number of objects
    return true;
    else // remove was unsuccessful
    return false;
    ErrorDialog
    import java.awt.*;
    import java.awt.event.*;
    class ErrorDialog extends Dialog implements ActionListener {
    private Label errorLabel = new Label("Message space here",Label.CENTER);
    private String errorMessage;
    private Button okButton = new Button("OK");
    public ErrorDialog(Frame frameIn, String message) {
    /* call the constructor of Dialog with the associated
    frame as a parameter */
    super(frameIn);
    // add the components to the Dialog
              errorLabel.setText(message);
              add("North",errorLabel);
    add("South",okButton);
    // add the ActionListener
    okButton.addActionListener(this);
    /* set the location of the dialogue window, relative to the top
    left-hand corner of the frame */
    setLocation(100,100);
    // use the pack method to automatically size the dialogue window
    pack();
    // make the dialogue visible
    setVisible(true);
    /* the actionPerformed method determines what happens
    when the okButton is pressed */
    public void actionPerformed(ActionEvent e) {
    dispose(); // no other possible action!
    } // end class
    I Know there are alot of files. Any help will be much appreciated. Once again, Many thanks in advance

    setSize (600, 200);orpack ();Kind regards,
      Levi
    PS:
        int i;
    parses to
    int i;
    , but
    [code]    int i;[code[i]]
    parses to
        int i;

  • Setting the value of a field based on a dropdown list

    I am using the latest production release of JHeadstart 10.1.3.0.91. I am trying to set the value of a field based on selecting the value of another field (drop down list). The drop down list field has the following attributes set autoSubmit="true" immediate="true" valueChangeListener="#{jhsPageLifecycle.updateModelValue}".
    The other field has the partialtrigger set to the first field. ie "depends on" selection from JHeadStart file. The value of the second field is set in the setter of the VO RowImpl java file.
    The value of that field is only populated on the screen if it is set to disabled="true". This seems a bit bizzare behaviour. Can you explain why it cannot set the value of the field when it is not disabled.

    Worked out that if i set the "Clear/Refresh value" attribute on the field that i want updated then it will work ok
    Alan

  • How to set the frame size?

    Hi,
    Can some one show me how to set the frame size in this program? History: I have created a window and added a button but its to small. So I want to increase the size of the frame to at least 600X400 pixel.
    private static void showGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("ButtonDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Create and set up the content pane.
            Main newContentPane = new Main();
            newContentPane.setOpaque(true); //content panes must be opaque
            frame.setContentPane(newContentPane);
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        }It would be nice if you could show me how to do it.
    Thank you very much for reading this.

    Challenger wrote:
    Simply adding
    frame.setSize(new Dimension(600,400));to the end of your code should work perfectly.Or, if you want to do it correctly, .setPreferredSize() on your frame before you .pack() it. The default layout manager for JFrame is BorderLayout, which uses the preferredSize of each component to calculate sizes during the .pack() call.

  • Can I set the stroke of an object to be on top/in front and the fill on the bottom/in back?

    Can I set the stroke of an object to be on top/in front and the fill on the bottom/in back?  I asked this question before and was told to go to appearance and drag the fill and stroke around as if they were a layer, but this did not bring my stroke to the top of the image.  Did I do this wrong somehow or is there another method?

    Erin,
    The default stacking order for an object with fill and stroke, such as a simple path, is that the stroke is on top and the fill is beneath it.
    You may change that in the Appearance palette, but it should not be necessary.
    Can you show a screenshot with the object and the Appearance palette and the Layers palette with the relevant (part of the) Layer expanded and visible?
    If things are really wrong, you may start considering going down this dark road:
    The following is a general list of things you may try when the issue is not in a specific file (you may have tried/done some of them already); 1) and 2) are the easy ones for temporary strangenesses, and 3) and 4) are specifically aimed at possibly corrupt preferences); 5) is a list in itself, and 6) is the last resort.
    1) Close down Illy and open again;
    2) Restart the computer (you may do that up to 3 times);
    3) Close down Illy and press Ctrl+Alt+Shift/Cmd+Option+Shift during startup (easy but irreversible);
    4) Move the folder (follow the link with that name) with Illy closed (more tedious but also more thorough and reversible);
    5) Look through and try out the relevant among the Other options (follow the link with that name, Item 7) is a list of usual suspects among other applications that may disturb and confuse Illy, Item 15) applies to CC, CS6, and maybe CS5);
    Even more seriously, you may:
    6) Uninstall, run the Cleaner Tool (if you have CS3/CS4/CS5/CS6/CC), and reinstall.
    http://www.adobe.com/support/contact/cscleanertool.html

  • How do I set the frame rate to 12fps on my video, and it not change randomly?

    Hi, I imported a video layer from file then set the frame rate to 12fps, when I play the video it keeps changing the frame rate to random times. How do I keep it at 12fps

    Click the windows start button, then right click on computer, this will bring up a window that will tell you how much ram your system has.
    Also Start>Accessories>System Tools>System Information will give you all the details you need to know.
    As for Codec, That is an abreviation for code/decode it tells windows how to code when saving a video and how to decode when playing a video. Most formats are wrappers (avi, wmv, mov, rt) Each of these have a codec that you can choose from when saving a video, that codec then must be installed on the users computer to see that same video. Most formats come with a basic number of codecs and the creator of the video can purchase other codecs that provide better feature set.
    What the codec really does is takes the video and compresses it like a zip file then the user when playing require that codec to uncompress it.
    So each codec has its own strength and weaknesses. Some can compress more making a smaller file and perhaps inturn removes more data to get that compression and therefore has a poorer quailty video (just an example)
    I am sure you heard of a few codecs if you think about it. mpg, mp2, mp3, mp4, h.264 and so on. Mp3 is the only one I listed here that is for audio only. Yep thats right even audio uses codecs.

  • Can i automatically set the timestamp of a file based on part of its filename?

    I have a bunch of files (approx. 500) with the same name pattern, that is : name_CreationDate.pdf. For instance: invoice015_2013_06_25.pdf or invitation035_2012_11_30.pdf. The last 10 digits are always the creation date. The original timestamps of the files have been messed up by a batch application which set them all to the same day; therefore they mean nothing anymore.
    Is there a way to automatically set the timestamp (for instance the "Creation Date" one) to the date indicated in the filename? I was thinking of Automator or some kind of shareware/freeware. Does anyone of you have an idea about this? Ideally as a batch rather than individually.
    Thanks,

    Thank you for your script. I made a test based on your script:
    a) I copied a PDF file on my desktop and named it "URSAFF 1er trim 2012_1998_09_19.pdf". The date component I want to set ultimately is therefore 1998_09_19.
    b) I created a service in Automator and pasted your script in a "Run a Shell Script" command. I added the Get Specified Finder Items at the beginning to be able to test the script on the file from Automator. (See screen shot of Automator below)
    c) The script appears to run successfully but I don't see a change in the timestamps of the file after I display Get Info from the Finder. (See screen shot of Get Info after I run the shell script)
    I wonder if my Region settings (I am based in France) do not interfere with the date/time string layout compatible with touch in your script. Just in case, I have added a capture of these settings.

  • How do you set the frame size?

    Trying to set a frame size for 1920px X 1080px but can't see where to set this in a new project?

    Frame dimensions are a property of the sequence, not the project. A project can contain multiple sequences with different properties.
    File>New>Sequence opens a dialog where you can choose a preset or configure custom settings. Several of the preset groups have 1920x1080 options.
    Asssuming you have footage of those dimensions that you'll be using in the sequence, then you can simply create a sequence from an asset. Either drag it to the New Item button in the Project panel's lower right corner, or right-click it and select New Sequence from Clip.

  • Does SSRS dynamically set the alignment of table cells based on the majority of cell types in the column???

    This is the first time I've run into this, but it appears that SSRS is setting the text-align based on the other cells in the column.  I have cells being set with either a dataset item of type System.Double or to "--" when Is Nothing evaluates
    to true.  I never noticed before that if the majority of the cells in the column are Nothing, then the few that aren't Nothing get aligned to the left along with all of the "--" text items.  And now I also see columns where the opposite
    is also happening, where if the majority of the cells in the column are numeric values, then everything is aligned right, even the few "--" items there.  I'm only using Default TextAlign and VerticalAlign, and no Indent, SpaceAfter or SpaceBefore,
    nor any concatenated text or embedded preserved spaces.
    Has anyone else in the SSRS universe seen this, and does anyone know why or have a good workaround for it?
    Thanks in advance : )

    Are you viewing the report in html format or are you looking in some other format like Excel,CSV etc?
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Set the value of a object in request scope

    I have the object in my req scope. I need to set value to one of the object attributes if that attribute is blank. How can I set its value.
    <c:set var="benefitVO" value="${requestScope.BenefitVO}" />I need to set the following Object attribute value, if it is blank.
    something like --- > benefitVO.setBnftCd("asdf");
    How can I set it using JSTL tags?
    any ideas
    Thanks

    I need to set value to one of the object attributes if that attribute is blank.This is some kind of a default value that you want, then? If so then just take care of that when you output it. Use <c:if>, and if the attribute is blank then output the default value, otherwise output the attribute.
    Or have the servlet that created that request attribute take care of that requirement.

  • Setting the visibility of check box based on values of dropdown field

    Dear Experts,
    I have to set the checkbox visible/hidden based on the values of dropdown field.
    Request you to please provide code example.
    Regards,
    Upendra

    Hi,
    For capturing the selected value from the dropdown (ComboBox in SAPUI5) field use the change event of the combobox UI element. Within this you can get the selected value using the getLiveValue() method of the combobox.
    Then depending on the value you can set the visible boolean property of your checkbox.
    Refer to the link ComboBox for more details.
    Regards,
    Saurabh

  • SETTING THE FRAME STYLE

    Do you know how you can change what buttons are available on the top right of the frame.
    As a default there are the three buttons: minimise, restore up/down and then close. How do you create a frame without these buttons and how do you create a frame with just the close button.
    I know that it can be done as you see frames like this everywhere.
    Manny thanks.

    a first guess:
    use a JFrame superclass:
    public class MyFrame extends JWindow
       //... code
       // you need to hand set all window appearence and
       // functionality
    }

  • Are the Frame or JFrame objects not supported when used by applets??????

    Hi,
    Is there anyone to help me ?
    I've an applet which uses Frame objects. With the "appletViewer" executable the results are
    perfect.
    But Netsacape Communicator seems not to support Frames..?!? Is this possible?????
    Thanks
    deniz

    Oh..Thanks for the replies.
    But the reason was that I was still using Netscape Communicator 4.5.
    With Netscape Communicator 6.1 installed yesterday; everything is
    normal. i.e. I can observe the frames that applet creates... :-))

  • How to set the Date and Currency Formats Based on Country

    Hi Friends,
    I am designing the one Global Form it will use for all countries.
    in that Form i want to print the date and currnecy Formats based on country.
    Like
    For US i want print the date and Currency Like This.
    Date -  MM/DD/YYYY
    Curremcy - XX,XXX,XX.XX
    For DE i want print the date and Currency Like This.
    Date -  DD.MM.YYYY
    Curremcy - XX.XXX.XX,XX
    Please suggest how i can control these things through Java Script or Formcalc....

    Hi Nitin,
    thanks For ur reply,
    i tried with this solution,
    But it is displaying the default Format like bellow formats.
    For short - mm/dd/yy
    For Medium - mmm dd , yyyy
    For Long     - thursday ,mmm dd , yyyy
    it was prinitng in above mentioned format,
    but here i want to print my own format for USA like MM/DD/YYYY.

  • Changing the image of parent object based on collection within

    Hi;
    I am working on SAP Work Manager 6.0 customising using Agentry 6.1.3. I have an object InspectionOrder, that has a collection of InspectionPoints, which in turn has a collection of InspectionTasks. I am working on having the images of these objects updated on tile lists on the device. I am using the windows .NET client for testing. Currently I have managed to have the InspectionTasks image to change to completed once the required fields have been filled in, I am using rules here. I have archieved this as follows:
    How can I possibly count the number of InspectionTasks with "Completed" image and compare this with the number of InspectionTasks in the collection, if the two are equal then this implies that all InspectionTasks within an InspectionPoint have been completed, and hence the InspectionPoint image must change to completed as well.
    Thanks in advance.
    Sizo Ndlovu

    Sizo,
    You can use the COUNT function against a collection.  You can also use selection criteria as a second parameter to COUNT to check the completed status:
    IF
         EQNUM
              COUNT
                   InspectionPoint Object -> InspectionTasks Collection
              COUNT
                   InspectionPoint Object -> InspectionTasks Collection
                        EQSTR
                             InspectionTask Object -> Status property
                             COMPLETED
    ImageComplete
    ImageIncomplete
    The above will compare the count of all tasks against the count of completed tasks and return the correct image name.
    Jason Latko - Senior Product Developer at SAP

Maybe you are looking for

  • Am not able to run the java program - pls help

    1. I installed java in the below path      c:\program files\java\jdk1.5.0      c:\program files\java\jre1.5.0 I set the path in      User variable i. variable name: path           ii. variable value: c:\program files\java\jdk1.5.0\bin when I compile

  • IE 11 - Sharepoint open in windows explorer not working

    In my IE 11 - Sharepoint open in windows explorer don't work. It appear always error message "Your client does not support opening this list with Windows Explorer" Already installed FIX ( http://support.microsoft.com/kb/2846960) Restart laptop Then S

  • Remote URL is not working from html embedded as3 code

    Hello, i am working on a flash currency converter application, for that purpose i am fetching the latest currency rates from yahoo, i am using flash cs5 and as3, i am getting the desired response from yahoo when i run the flash file from Flash cs5 (c

  • Macbook pro 17 [early 2009] information

    Hi everyone, I'm about to buy a Macbook Pro 17" but before buying it I would like to have my information confirmed, so I'll summarize it (this will also help everyone who wants to buy a Macbook Pro 17" too). I'm aware that the problems I'll speak abo

  • Deletion of Release Group and Code in PO

    Dear Consultant, In Purchase order, we have created some release group and code, Unfortunately we deleted some groups Without deleting in Order wise. In table level the Release Group is there but in SPRO Release Strategy settings its not there..My co