AS3 loadVars and arrays

I have a text file with variables and an swf that a friend made for me. Unfortunately i dont have the .fla file and i am trying to recreate it.
the file contains 3 variables with values, repeated 4 times and a final variable (called varDone) that tells it there are no more variables.
The three variables are varImage, varURL, varText. These are used to load images that can be clicked to open a website and they have a textfield above them.
The flash is a banner that we use on our site to display these images. Somehow, he reads the first set of variables into a movieclip i believe, where the image then fades in and stays on screen for 3 more seconds and then goes onto the next image. He keeps reading variables from the file until he hits that varDone=1 variable, then the banner starts all over. The file is such that I can add as many sets of variables as i want, and it will display all of them, it could be 3 or 10 or 30, as long as i add a new set of (varImage, varURL, varText) to the file ahead of the varDone variable. I thought maybe he might be loading those 3 variables into a two dimensional array and then processing them that way. This is the part I don't know how to do, how to read each set of variables, until i get to the varDone=1. I can do all the other stuff, I just don't know how to read this file.
It looks like the following:
&varImage=http://www.mofc-gaming.com/themes/CT_RN_GREYSCALE/images/spotlight1.jpg
&varHeadline=RECRUITING BAD COMPANY 2 MEMBERS
&varLink=http://badcompany2.ea.com/#/home
&varImage=http://www.mofc-gaming.com/themes/CT_RN_GREYSCALE/images/spotlight2.jpg
&varHeadline=Join MOFC in EVE Online
&varLink=http://www.eveonline.com
&varDone=1

XML is what you want.  You would get a 1D array (not 2D - no need for 2D at all).  An xml file like this would suffice:
<Pics>
     <image url="www.image1.jpg"> Text to display along with Image could go here.</image>
     <image url="www.image1.jpg"> Text to display along with Image could go here.</image>
     <image url="www.image1.jpg"> Text to display along with Image could go here.</image>
</Pics>
Then in Flash, you load the xml file and the resulting XML object you get can be parsed liek this:
_xmlObject.image;   <-returns an XMLList of all 'image' nodes in the xml document.
_xmlObject.image[0];      <-returns the first XML Object found in the XMLList described above.  When treated as a String it will output "Text to display along with Image could go here."
_xmlObject.image.@url[0]    <- returns the string "www.image1.jpg"
This will teach you everything you need to know: http://www.kirupa.com/developer/flashcs3/using_xml_as3_pg1.htm
Hope this helps.  For AS3 nothing beats XML for loading dynamic data.

Similar Messages

  • All the xml and arrays are getting NULL Problem

    Hello guys
    I am working on a project which uses xml loading, e4x and array manipulation extensively, and it was going good but now I got stuck on a strange problem.  Whole code was fine and application was working and responding in a desired way, but then mystourisly it stopped working and started to retun NULL values to almost all the actionscript (internal) Arrays and XML varibales.
    Now Whenever i load xml file and assign the loaded values to internal xml variables, internal values get only NULL instead of data.
    Same is the situation with Arrays, I created some components in mxml, and when i passed them to arrays by reference, code gets compiled successfully, but again Array has only null values [that code was working fine too]
    I am wondering if Adobe Flex did a silenced update or something similar and it is the result of that things !
    I am using Adobe Flex 3.2 with SDK 3.3 on windows Vista Ultimate.
    Please check this attached project, Import it and see if you face the same problem
    Thanks
    Link to Problem Project
    http://isolatedperson.googlepages.com/problemXperiment.zip
    Problem Screenshot
    http://isolatedperson.googlepages.com/xmlissue.JPG

    Use HTTPService to load the data. You'll have fewer problems.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application creationComplete="dataSvc.send();"
      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
         <mx:Script>
              <![CDATA[
                import mx.collections.XMLListCollection;
                import mx.rpc.events.ResultEvent;
                [Bindable] private var xlc:XMLListCollection;
                   private function loadXML(evt:ResultEvent):void{
                    xlc =  new XMLListCollection(evt.result.individual.@id as XMLList);
              ]]>
         </mx:Script>
         <mx:HTTPService resultFormat="e4x" result="loadXML(event)" url="alirazaTree.xml" id="dataSvc"/>
         <mx:ComboBox id="cbx" dataProvider="{xlc}"/>
    </mx:Application>

  • Loops and Arrays help

    Hi,
    I'm a freshman in college and new to java. I am completely lost and really need help with a current assignment. Here are the instructions given by my teacher...
    Building on provided code:
    Loops and Arrays
    Tracking Sales
    Files Main.java and Sales.java contain a Java application that prompts for and reads in the sales for each of 5 salespeople in a company. Files Main.java and Sales.java can be found here http://www.ecst.csuchico.edu/~amk/foo/csci111/labs/lab6N/Main.java
    and here http://www.ecst.csuchico.edu/~amk/foo/csci111/labs/lab6N/Sales.java It then prints out the id and amount of sales for each salesperson and the total sales. Study the code, then compile and run the program to see how it works. Now modify the program as follows:
    1. (1 pts) Compute and print the average sale. (You can compute this directly from the total; no new loop is necessary.)
    2. (2 pts) Find and print the maximum sale. Print both the id of the salesperson with the max sale and the amount of the sale, e.g., "Salesperson 3 had the highest sale with $4500." Note that you don't necessarily need another loop for this; you can get it in the same loop where the values are read and the sum is computed.
    3. (2 pts) Do the same for the minimum sale.
    4. (6 pts) After the list, sum, average, max and min have been printed, ask the user to enter a value. Then print the id of each salesperson who exceeded that amount, and the amount of their sales. Also print the total number of salespeople whose sales exceeded the value entered.
    5. (2 pts) The salespeople are objecting to having an id of 0-no one wants that designation. Modify your program so that the ids run from 1-5 instead of 0-4. Do not modify the array-just make the information for salesperson 1 reside in array location 0, and so on.
    6. (8 pts) Instead of always reading in 5 sales amounts, allow the user to provide the number of sales people and then create an array that is just the right size. The program can then proceed as before. You should do this two ways:
    1. at the beginning ask the user (via a prompt) for the number of sales people and then create the new array
    2. you should also allow the user to input this as a program argument (which indicates a new Constructor and hence changes to both Main and Sales). You may want to see some notes.
    7. (4 pts) Create javadocs and an object model for the lab
    You should organize your code so that it is easily readable and provides appropriate methods for appropriate tasks. Generally, variables should have local (method) scope if not needed by multiple methods. If many methods need a variable, it should be an Instance Variable so you do not have to pass it around to methods.
    You must create the working application and a web page to provide the applications information (i.e., a page with links to the source code, the javadoc and an object model) to get full credit. You can use the example.html's from the last two labs to help you remember how to do this.
    I'm not asking for someone to do this assignment for me...I'm just hoping there is someone out there patient and kind enough to maybe give me a step by step of what to do or how to get started, because I am completely lost from the beginning of #1 in the instructions.
    Any help would be much appreciated! Thank you!
    Message was edited by:
    Scott_010
    Message was edited by:
    Scott_010

    First ask the person who gave this asignment as to why do you require two classes for this , you can have only the Sales.java class with main method in it . Anyways.
    Let Main.java have a main method which instanciates a public class Sales and calls a method named say readVal() in Sales class.
    In the readVal method of sales class define two arrays i.e ids and sales. Start prompting the user for inputting the id and sales and with user inputting values keep storing it in the respective arrays .. Limit this reading to just 5 i.e only 5 salesPerson.
    Once both the arrays are populated, call another method of Sales class which will be used for all computations and output passing both the arrays.
    In this new method say Compute() , read values from array and keep calculating total,average and whatever you want by adding steps in just this loop. You can do this in readval method too after reading the values but lets keep the calculation part seperate from input.
    You must create the working application and a web page to provide the applications information (i.e., a page with links to the source code, the javadoc and an object model) to get full credit. You can use the example.html's from the last two labs to help you remember how to do this. I think this is ur personal stuff , but if you want to use web page , you probably will require to use servlet to read values from the html form passed to the server.

  • Challeging Traversal of Vector and Array

    Hi there ! I would like to render the values of this Vector and Array . How do I print it out to the browser ?
    try
    ResultSet rset = stmt.executeQuery(myQuery);
    System.out.println(" Finish Execute Query !!! ");
    /* Array Contruction */
    int numColumns = rset.getMetaData().getColumnCount();
    while (rset.next())
    aRow = new String[numColumns];
    for (int i=0; i < numColumns; i++){
    aRow[i] = rset.getString(i+1);
    allRows.addElement(aRow);
    return allRows;
    }

    Hi there !
    Thanks for your help but I managed to get it working. For references purposes, I`ll post it here.
    My problem now is this :-
    How can I issue another SQL statement and store the results in the same array?
    Pls note . One Sql per table so, that`s the issue ?
    Can someone help with a followup code ?
    try
    ResultSet rset = stmt.executeQuery(myQuery);
    System.out.println(" Finish Execute Query !!! ");
    /* Array Contruction */
    int numColumns = rset.getMetaData().getColumnCount();
    while(rset.next())
    // for every record instance aRow
    aRow = new String[numColumns];
    // store in aRow the values of the record
    for(int i=0;i<numColumns;i++)
    aRow[i] = rset.getString(i+1);
    //When aRow is full store it in the vector
    allRows.addElement(aRow);
    // when the rset finished print all the Vector
    for(int i=0;i<allRows.size();i++)
    // get returns a String[]
    String[] tmpRow = (String[])allRows.get(i);
    for(int j=0;j<tmpRow.length;j++)
    out.print(tmpRow[j]+" ");
    out.println("");
    }

  • NXT Flatten to String Not Working with Clusters and Arrays

    Hello,
    My name is Joshua and I am from the FIRST Tech Challenge Team 4318, Green Machine. We are trying to write a program that will write to a configuration file and read it back. The idea is that we will be able to write to a config file from our computer that will be read by our autonomous program when it runs. This will define what the autonomous program does.
    The easiest way to do this seems to be flattening a data structure to a string, saving it to a file, and then reading back and unflattening it. The issue is that the flatten to string and unflatten from string VIs don't seem to work with arrays and clusters on the NXT. It does work when running on the computer. We've tried arrays, clusters, clusters in arrays and arrays in clusters, none seem to work. Thinking it was something to do with reading the string from a file, we tried bypassing the file functionality, still not working. It does work with basic data types though, such as strings and numbers.
    No error is thrown from what we can tell. All you get is a blank data structure out of the unflatten VI.
    The program attached is a test program I've been working on to get this functionality to work. It will display the hex content of what is going into the file, coming out of the file, and then the resulting data from the unflatten string, as well as any errors that have been thrown. The data type we are using simulates what we would like to store. There is also a file length in and out counter. The out file is a little larger because the NXT write file VI adds a new line character on to the end (thus the use of the strip white space VI). This character was corrupting even basic data types saved to file.
    I would like to know if there is a problem with what we are doing, or if it is simply not possible to flatten arrays on the NXT. Please ask if you have any questions about the code. Thank you in advanced!
    Joshua
    Attachments:
    ReadableTest.vi ‏20 KB

    Hi jfireball,
    This is a very interesting situation. Take a look at what kbbersch said. I also urge you to post in the FTC Forums. You posted your question to the general LabVIEW forums, but by posting to the FTC Forums, you will have access to others that are using the NXT hardware.
    David B.
    Applications Engineer
    National Instruments

  • LoadVars and listener functions

    Hi all...I posted yesterday with some trouble getting
    loadvariables to work. I have since changes the code to use the
    LoadVars class instead but I am still have the same issue as
    before. The request for variables from the server does not complete
    and the values do not get set before the variables need to be used.
    I have a simple flash movie with 1 input text box (name_txt),
    1 button (Submit) and 1 dynamic text box (lblOutput).
    I have a simple script on the button:
    on (release) {
    //loadVariables("dev.aspx?foo=" + name_txt.text, "POST");
    newVars = new LoadVars();
    newVars.load("dev.aspx?foo="+_level0.name_txt.text);
    //This line just visually shows me that the script makes it
    this far
    _level0.lblOutput.text += "This is hard coded
    text.<br>";
    _level0.lblOutput.text += newVars.retVal;
    I have a very simple asp page that returns the value:
    'Format the response
    Response.ContentType = "application/x-www-form-urlencoded"
    'Create a string and
    Dim foo As String = "&retVal=" &
    Request.QueryString("foo") & " - This is from the ASP
    Page.<br>"
    Trace.Warn(foo.ToString)
    Response.Write(foo.ToString)
    Response.End()
    When I load the Flash movie and type the word "test" into the
    input field and click submit...I can see that Flash sends the
    variable to the asp page by checking the asp trace information. The
    value comes into asp just fine but, as I understand it, I need some
    sort of listener function to force Flash to wait for the
    transaction to complete before trying to load the use the variable
    values.
    Could someone please explain how I can add this listener
    functionality to the script above? Many thanks!!

    You need a stop() on the frame doing the load and onLoad.
    Then in the onLoad
    you move to the next frame. Other approaches include hiding
    the UI and in
    the onLoad, revealing the UI such as a MovieClip cover is
    made invisible.
    Declare the results LoadVars object on the timeline outside
    of a function
    and it is accessible for the entire movie at all levels.
    Lon Hosford
    www.lonhosford.com
    May many happy bits flow your way!
    "nagromme" <[email protected]> wrote in
    message
    news:e4fpvm$qmq$[email protected]..
    I'm using LoadVars in Frame 1, and I need to use the
    resulting variables in
    other scripts afterwards. (But all the examples I find online
    only use the
    variables right in the same script.)
    The problem I'm having is, the onLoad function doesn't
    actually make it
    wait.
    It goes ahead to the next frame whether fully loaded or not.
    It depends on
    the
    connection at the moment--if the vars haven't fully loaded,
    hilarity ensues.
    <b>My script in Frame 1:</b>
    _root.myloadvars = new LoadVars();
    _root.myloadvars.load("datapairs.txt");
    _root.myloadvars.onLoad = function(success) {
    if (success) {
    //trace("TXT RETRIEVED");
    gotoAndPlay(2);
    } else {
    trace("TXT NOT RETRIEVED");
    gotoAndPlay(1);
    <b>It's SUPPOSED to hold in Frame 1 until ready to
    proceed and make use of
    the
    variables in Farme 2.
    Things I have tried:</b>
    * Moving the above to Frame 2, so the "not retrieved" loop
    actually has two
    frames to cycle (back to 1, then forward to 2 where the
    script it).
    * Adding an additional gotoAndPlay(1) BELOW the above.
    But regardless, it never goes back to Frame 1, it always
    goes forward. It
    reports success, but half the time the variables (or some of
    them) are still
    Undefined.
    What's the RIGHT way to wait in a frame for LoadVars, and
    then let other
    scripts use the variables afterwards?
    <b>Many thanks for any advice!</b>
    (PS, this is Flash MX--I'm waiting for Universal Binary
    before I upgrade.)

  • Strange behaviour of "And array Elements"

    If u connect an empty boolean array to "And Array Elements" function, The output is "True" !. Is this correct?. Is there something wrong ?. Please Help.

    Hi J.A.C
    This is correct.This is an explanation I've found: "This behavior is intentiional, and stems from elementary Boolean logic. The Boolean algebra primitives are analogous to numeric operations are integers. Just as the identity element for addition is 0, and for multiplication, 1; the identity for Boolean OR is FALSE, and for AND, TRUE. For example, x^0 == 1; that is, x times itself zero times is by definition 1. For the same reason boolean x ANDed with itself zero times is TRUE."
    If this is not acceptable for your application, then just use the "Array Size" VI first to check if you've an empty Array (Array size=0) and then you can pass or not the array to the "And Array Elements" function.
    Hope this helps.
    Luca
    Regards,
    Luca

  • Problems launching Object Manager and Array Manager in SSGD 4.20.983

    Hi,
    I have just installed SSGD 4.20.983 in a server which is running Solaris 10. The language of this server is Spanish.
    When I access to the webtop, I 'm not be able to launch the applications Object Manager and Array Manager.
    When I try to launch them, in the details box appears "Contrase�a" and them the timeout expires. Contrase�a is the same that password in Spanish.
    Anyone can help me?
    Regards,
    Diego

    Do you have any logfiles which look like : execpePID_error.log?
    These files should contain more information.
    Also take a look at the following section of the Administration Guide: [http://docs.sun.com/source/820-6689/chapter4.html#d0e21816]
    Especially the part '+Increasing the Log Output+'
    - Remold

  • LoadVars and onLoad question

    I'm using LoadVars in Frame 1, and I need to use the
    resulting variables in other scripts afterwards. (But all the
    examples I find online only use the variables right in the same
    script.)
    The problem I'm having is, the onLoad function doesn't
    actually make it wait. It goes ahead to the next frame whether
    fully loaded or not. It depends on the connection at the moment--if
    the vars haven't fully loaded, hilarity ensues.
    My script in Frame 1:
    _root.myloadvars = new LoadVars();
    _root.myloadvars.load("datapairs.txt");
    _root.myloadvars.onLoad = function(success) {
    if (success) {
    //trace("TXT RETRIEVED");
    gotoAndPlay(2);
    } else {
    trace("TXT NOT RETRIEVED");
    gotoAndPlay(1);
    It's SUPPOSED to hold in Frame 1 until ready to proceed and make
    use of the variables in Farme 2.
    Things I have tried:
    * Moving the above to Frame 2, so the "not retrieved" loop
    actually has two frames to cycle (back to 1, then forward to 2
    where the script it).
    * Adding an additional gotoAndPlay(1) BELOW the above.
    But regardless, it never goes back to Frame 1, it always goes
    forward. It reports success, but half the time the variables (or
    some of them) are still Undefined.
    What's the RIGHT way to wait in a frame for LoadVars, and
    then let other scripts use the variables afterwards?
    Many thanks for any advice!
    (PS, this is Flash MX--I'm waiting for Universal Binary
    before I upgrade.)

    You need a stop() on the frame doing the load and onLoad.
    Then in the onLoad
    you move to the next frame. Other approaches include hiding
    the UI and in
    the onLoad, revealing the UI such as a MovieClip cover is
    made invisible.
    Declare the results LoadVars object on the timeline outside
    of a function
    and it is accessible for the entire movie at all levels.
    Lon Hosford
    www.lonhosford.com
    May many happy bits flow your way!
    "nagromme" <[email protected]> wrote in
    message
    news:e4fpvm$qmq$[email protected]..
    I'm using LoadVars in Frame 1, and I need to use the
    resulting variables in
    other scripts afterwards. (But all the examples I find online
    only use the
    variables right in the same script.)
    The problem I'm having is, the onLoad function doesn't
    actually make it
    wait.
    It goes ahead to the next frame whether fully loaded or not.
    It depends on
    the
    connection at the moment--if the vars haven't fully loaded,
    hilarity ensues.
    <b>My script in Frame 1:</b>
    _root.myloadvars = new LoadVars();
    _root.myloadvars.load("datapairs.txt");
    _root.myloadvars.onLoad = function(success) {
    if (success) {
    //trace("TXT RETRIEVED");
    gotoAndPlay(2);
    } else {
    trace("TXT NOT RETRIEVED");
    gotoAndPlay(1);
    <b>It's SUPPOSED to hold in Frame 1 until ready to
    proceed and make use of
    the
    variables in Farme 2.
    Things I have tried:</b>
    * Moving the above to Frame 2, so the "not retrieved" loop
    actually has two
    frames to cycle (back to 1, then forward to 2 where the
    script it).
    * Adding an additional gotoAndPlay(1) BELOW the above.
    But regardless, it never goes back to Frame 1, it always
    goes forward. It
    reports success, but half the time the variables (or some of
    them) are still
    Undefined.
    What's the RIGHT way to wait in a frame for LoadVars, and
    then let other
    scripts use the variables afterwards?
    <b>Many thanks for any advice!</b>
    (PS, this is Flash MX--I'm waiting for Universal Binary
    before I upgrade.)

  • Performance of System.arraycopy and Arrays.fill

    I have some code where I call a function about 1,000,000 times. That function has to allocate a small array (around 15 elements). It would be much cheaper if the client could just allocate the array one single time outside of the function.
    Unfortunately, the function requires the array to have all of its elements set to null. With C++, I would be able to memset the contents of the array to null. In Java, the only methods I have available to me are System.arraycopy() and Arrays.fill().
    Apparently, Arrays.fill() is just a brain-dead loop. It costs more for Arrays.fill() to set the elements to null than it does to allocate a new array. (I'm ignoring possible garbage collection overhead).
    System.arraycopy is a native call (that apparently uses memcpy). Even with the JNI overhead, System.arraycopy runs faster than Arrays.fill(). Unfortunately, it's still slower to call System.arraycopy() than it is to just allocate a new array.
    So, the crux of the problem is that the heap allocations are too slow, and the existing means for bulk setting the elements of an array are even slower. Why doesn't the virtual machine have explicit support for both System.arraycopy() and Arrays.fill() so that they are performed with ultra-efficient memsets and memcpys and sans the method call and JNI overhead? I.E. something along the lines of two new JVM instructions - aarraycpy/aarrayset (and all of their primitive brethern).
    God bless,
    -Toby Reyelts

    A newly allocated array begins its life with null in its elements. There is no need to fill it with null.
    As Michael already stated, I'm not redundantly resetting all of the elements to null. Here's some code that demonstrates my point. You'll have to replace my PerfTimer with your own high performance timer. (i.e. sun.misc.Perf or whatever) Also note that the reason I'm only allocating half the array size in allocTest is to more accurately model my problem. The size of the array I need to allocate is variable. If I allocate the array outside of the function, I'll have to allocate it at a maximum. If I allocate inside the function, I can allocate it at exactly the right size.import java.util.*;
    public class AllocTest {
      private static final int count = 100000;
      public static void main( String[] args ) {
        for ( int i = 0; i < 10; ++i ) {
          allocTest();
        double allocStartTime = PerfTimer.time();
        allocTest();
        double allocTime = PerfTimer.time() - allocStartTime;
        for ( int i = 0; i < 10; ++i ) {
          copyTest();
        double copyStartTime = PerfTimer.time();
        copyTest();
        double copyTime = PerfTimer.time() - copyStartTime;
        for ( int i = 0; i < 10; ++i ) {
          fillTest();
        double fillStartTime = PerfTimer.time();
        fillTest();
        double fillTime = PerfTimer.time() - fillStartTime;
        System.out.println( "AllocTime (ms): " + allocTime / PerfTimer.freq() * 1000 );
        System.out.println( "CopyTime (ms): " + copyTime / PerfTimer.freq() * 1000 );
        System.out.println( "FillTime (ms): " + fillTime / PerfTimer.freq() * 1000 );
      private static void allocTest() {
        for ( int i = 0; i < count; ++i ) {
          Object[] objects = new Object[ 8 ];
      private static void copyTest() {
        Object[] objects = new Object[ 15 ];
        Object[] emptyArray = new Object[ 15 ];
        for ( int i = 0; i < count; ++i ) {
          System.arraycopy( emptyArray, 0, objects, 0, emptyArray.length );
      private static void fillTest() {
        Object[] objects = new Object[ 15 ];
        for ( int i = 0; i < count; ++i ) {
          Arrays.fill( objects, null );
    }I getH:\>java -cp . AllocTest
    AllocTime (ms): 9.749283777686829
    CopyTime (ms): 13.276827082771694
    FillTime (ms): 16.581995756443906So, to restate my point, all of these times are too slow just to perform a reset of all of the elements of an array. Since AllocTime actually represents dynamic heap allocation its number is good for what it does, but it's far too slow for simply resetting the elements of the array.
    CopyTime is far too slow for what it does. It should be much faster, because it should essentially resolve to an inline memmove. The reason it is so slow is because there is a lot of call overhead to get to the function that does the actual copy, and that function ends up not being an optimized memmove. Even so, one on one, System.arraycopy() still beats heap allocation. (Not reflected directly in the times above, but if you rerun the test with equal array sizes, CopyTime will be lower than AllocTime).
    FillTime is unbelievably slow, because it is a simple Java loop. FillTime should be the fastest, because it is the simplest operation and should resolve to an inline memset. Fills should run in single-digit nanosecond times.
    God bless,
    -Toby Reyelts

  • Append variable and array items after a record array search

    I would like to update a variable and array item after a record array search, and wanted to know what would be the best way of carrying it out in Javascript.
    In this case, if a match is found between the variable and area item, then the postcode item should be appended to the variable.
    The same needs to be done for the array items, but I reckon that a for loop would work best in this scenario, as each individual item would need to be accessed somehow.
    Btw due to the nature of my program, there will always be a match. Furthermore, I need to be able to distinguish between the singleAddress and multipleAddresses variables.
    Hopefully this code explains things better:
    // before search
    var singleAddress = "Mount Farm";
    var multipleAddresses = ["Elfield Park", "Far Bletchley", "Medbourne", "Brickfields"];
    // this is the record which the search needs to be run against
    plot = [{
    postcode: "MK1",
    area: "Denbigh, Mount Farm",
    postcode: "MK2",
    area: "Brickfields, Central Bletchley, Fenny Stratford, Water Eaton"
    postcode: "MK3",
    area: "Church Green, Far Bletchley, Old Bletchley, West Bletchley",
    postcode: "MK4",
    area: "Emerson Valley, Furzton, Kingsmead, Shenley Brook End, Snelshall West, Tattenhoe, Tattenhoe Park, Westcroft, Whaddon, Woodhill",
    postcode: "MK5",
    area: "Crownhill, Elfield Park, Grange Farm, Oakhill, Knowlhill, Loughton, Medbourne, Shenley Brook End, Shenley Church End, Shenley Lodge, Shenley Wood",
    // after search is run then:
    // var singleAddress = "Mount Farm, MK1"
    // var multipleAddresses = ["Elfield Park, MK5", "Far Bletchley, MK3", "Medbourne, MK5", "Brickfields, MK2"]
    Fiddle here

    I would like to update a variable and array item after a record array search, and wanted to know what would be the best way of carrying it out in Javascript.
    In this case, if a match is found between the variable and area item, then the postcode item should be appended to the variable.
    The same needs to be done for the array items, but I reckon that a for loop would work best in this scenario, as each individual item would need to be accessed somehow.
    Btw due to the nature of my program, there will always be a match. Furthermore, I need to be able to distinguish between the singleAddress and multipleAddresses variables.
    Hopefully this code explains things better:
    // before search
    var singleAddress = "Mount Farm";
    var multipleAddresses = ["Elfield Park", "Far Bletchley", "Medbourne", "Brickfields"];
    // this is the record which the search needs to be run against
    plot = [{
    postcode: "MK1",
    area: "Denbigh, Mount Farm",
    postcode: "MK2",
    area: "Brickfields, Central Bletchley, Fenny Stratford, Water Eaton"
    postcode: "MK3",
    area: "Church Green, Far Bletchley, Old Bletchley, West Bletchley",
    postcode: "MK4",
    area: "Emerson Valley, Furzton, Kingsmead, Shenley Brook End, Snelshall West, Tattenhoe, Tattenhoe Park, Westcroft, Whaddon, Woodhill",
    postcode: "MK5",
    area: "Crownhill, Elfield Park, Grange Farm, Oakhill, Knowlhill, Loughton, Medbourne, Shenley Brook End, Shenley Church End, Shenley Lodge, Shenley Wood",
    // after search is run then:
    // var singleAddress = "Mount Farm, MK1"
    // var multipleAddresses = ["Elfield Park, MK5", "Far Bletchley, MK3", "Medbourne, MK5", "Brickfields, MK2"]
    Fiddle here

  • Using a function and array to remove stage instances

    I'm trying to figure out the best way to handle this.
    I have an array of items I want to be looked through and removed if a specific function is running and if the stage contains them.
    removalArray = [axScene, bridgeScene];
    public function Removal(event:Event) {
                trace("cheese");
                for (var i:uint = 0; i>removalArray.length; i++) {
                    if (stage.contains(removalArray[i])) {
                        removeChild(removalArray[i]);
                        removeEventListener(Event.ENTER_FRAME, Removal);
                        addEventListener(Event.ENTER_FRAME, CampScene);
                    } else {
                        removeEventListener(Event.ENTER_FRAME, Removal);
                        addEventListener(Event.ENTER_FRAME, CampScene);/**/
    addEventListener(Event.ENTER_FRAME, Removal);
    I'm able to get trace("cheese"); to work at its current position, but the function does not seem to like my "for" and "if" statements because putting trace("cheese") amongst them does not work.
    As always, help is appreciated, and let me know if you need more info.
    EDIT: Perhaps I should also note I am able to get
    if (stage.contains(axScene)) {
                    removeChild(axScene);
                    } else if (stage.contains(bridgeScene)) {
                        removeChild(bridgeScene);
                        } else {
                            null;
    to work correctly in that function.
    EDIT2: Would this have something to do with addChild only being able to remove one instance at a time? I can't imagine that's it since this suppose to be run through a loop.

    You appear to have an unhealthy obsession with using the ENTER_FRAME event. 
    I'm sure you're right, but realize that I'm learning by the seat of my pants and am not great with logic and stuff that doesn't happen chronological. (I'm 26, and graduated with a degree in graphic design.) If I find something that works I'm going to keep using that until I find a better way, and thus far ENTER_FRAME has been all I've had. (I can find tons of AS3 information online, but a lot of it is forum posts seems to be lacking useful context for my purposes.)
    For what it's worth (if you remember another post I did that had a ton of event listeners), I've started using more booleans and gotten rid of a lot of listeners adding and removing.
    What you might try doing instead of creating all manners of them is to have just one and within that one you manage your objects using conditionals.
    So something like this?
    if (campSceneOnStage == true) {
         addChild(campScene)
         } else if (campSceneOnStage == false) {
              removeChild(campScene);
    EDIT: Although this would keep adding a campScene instance, wouldn't it?
    EDIT2: Could I write something like this, have one constant event listener (addEventListener(Event.ENTER_FRAME, Scenes)...
    public function Scenes(event:Event) {
                if (campSceneOn == true) {
                    addChild(campScene);
                    if (stage.contains(campScene)) {
    and use a line to tell the function to temporarily stop listening if campSceneOn = true and campScene is on the stage?
    Would "null" work?
    Also, is there an equivalent to "stage.contains" that looks to see if the stage does not contain?
    That ENTER_FRAME listener is being removed as fast as it was added, whether or not there is something in the array to remove.
    So the even though the intention is to only have the removeEventListener only occur if something is found in the array to remove, the script "skips over" that and removes the event listener even if it doesn't "use" the for loop or if statements?

  • AS3 centering and resizing a background in existing code

    I have a code for a page I am using and I would like to add a background and have it resize with the screen like the rest of the page.  I have created a movie button named "pic" with the image in it but I don't know how to write the code and place it in the existing AS3 code file.  Could someone please help.  I am brand new to this so if someone could tell me how to place the code like i was in 3rd grade, that would be great. Here is the existing code.
    package com.modules
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.text.*;
    import caurina.transitions.Tweener;
    import com.utils.*;
        public class About extends Sprite
    private var content_height:int;
    private var content_width:int;
    private var marginTop:int;
    private var marginBottom:int;
    private var content_y:int;
    private var _content:Content;
    private var news:News;
    private var array:Array;
    private var pan:Panning;
       public function About()
    // listen for when this is added to stage
    this.addEventListener(Event.ADDED_TO_STAGE, ini); 
    // listen for when this is removed from stage
    this.addEventListener(Event.REMOVED_FROM_STAGE, remove);
    private function ini(e:Event)
    stage.addEventListener(Event.ADDED, onStageResize);
    stage.addEventListener(Event.RESIZE, onStageResize);
    content_y = int(GlobalVarContainer.vars.CONTENT_Y);
    _content = new Content;
    addChild(_content);
    _content.visible=false;
    // load xml
    if((GlobalVarContainer.vars.XML_PATH!="") && (GlobalVarContainer.vars.XML_PATH!=undefined))
    var loadXml:LoadXml;
    loadXml = new LoadXml(GlobalVarContainer.vars.XML_PATH);
    loadXml.addEventListener(Event.COMPLETE, onXmlComplete);
    private function onXmlComplete(e:Event)
    // set up content
    content_width = e.target.returnData.attribute("width");
    marginTop = e.target.returnData.attribute("marginTop");
    marginBottom = e.target.returnData.attribute("marginBottom");
    var backgroundColor = e.target.returnData.attribute("backgroundColor");
    Tweener.addTween(_content.bg, {_color:backgroundColor, time:.1, transition:"linear"});
    _content.bg.width = content_width;
    _content.masc.area.width = (content_width -_content.masc.x)-20;
    _content.holder.txt.width = _content.masc.area.width -10;
    // write text
    _content.holder.txt.mouseWheelEnabled = false;
    _content.holder.txt.styleSheet = GlobalVarContainer.vars.CSS;
    _content.holder.txt.condenseWhite = true;
    _content.holder.txt.htmlText = e.target.returnData;
    _content.holder.txt.autoSize = TextFieldAutoSize.LEFT;
    onStageResize();
    _content.visible=true;
    // create new Panning instance;
    pan = new Panning(_content.holder, _content.masc, _content.bg, 4, true);
    pan.addEventListener(Event.ADDED, scInit);
    addChild(pan);
    // Initialize panning
    function scInit(e:Event):void
    pan.init();
    // resize contents
    private function onStageResize(e:Event = null):void
    resizeContent((stage.stageHeight - ((content_y + marginTop) + int(GlobalVarContainer.vars.BOTTOM_SHAPE_H)))-marginBottom);
    private function resizeContent(height_:int):void
    content_height = height_;
    _content.bg.height = content_height;
    _content.masc.area.height = (content_height -_content.masc.y)-20;
    _content.holder.mask = _content.masc;
    Tweener.addTween(_content, {x: Math.round(stage.stageWidth/2 - _content.width/2) , time:.5, transition:"linear"});
    _content.y=content_y+ marginTop;
    // used to change colors. here we not use
    public function changeTheme():void
    // remove listeners, images and unload panning;
    function remove(event: Event) : void
    pan.unload();
    stage.removeEventListener(Event.ADDED, onStageResize);
    stage.removeEventListener(Event.RESIZE, onStageResize);
    this.removeEventListener(Event.ADDED_TO_STAGE, ini); 
    this.removeEventListener(Event.REMOVED_FROM_STAGE, remove);
    trace("remove about");

    I just wanted to say that the above code works fine, I just need to add the resizing background code to it. Please help.  thanks

  • Loops and arrays

    Hi
    I'm trying to write a loop that does the following :-
    Takes an array of index values that applies to a string adds one to the value of the index and then returns the character in this position.
    There are only four types of character within the string so I have tried to solve it with the following code:-
    for (int i=0; i < indexa.length; i++)
        if(genome.charAt(indexa[i] + 1) == 'a')
            indexia[i] += indexa;
    else if(genome.charAt(indexa[i] + 1) == 'c')
    indexic[i] += indexa[i];
    else if(genome.charAt(indexa[i] + 1) == 'g')
    indexig[i] += indexa[i];
    else if (genome.charAt(indexa[i] + 1) == 't')
    indexit[i] += indexa[i];
    I'm trying it this way but it does'nt seem to work - I've only succeeded in confusing myself - any tips would be much appreciated

    Sorry, I should have explained it better.
    The situation I've got is something like this:-
    I've got a string that looks something like this
    'aactgctcct'
    next - I've got four different arrays, each corresponding to the index of each character a, c, t and g
    so they look something like this
    indexa = {0,1}
    indexc = {2,5,7,8}
    indext = {3,6,9}
    indexg = {4}
    I am presently stuck at the next part - for which I have to return the character that is to the immediate right of the index value in the string that was analysed initially.
    e.g. for indexa ;
    0 = a
    1 = c
    for indexc;
    2 = t
    5 = t
    7 = c
    8 = t
    etc
    I don't know if this makes my predicament any clearer - I'm a genetics student this java is very new to me - I'm kinda muddling through but this bit has got me stumped !!!

  • Problem with java applet and array of arrays

    hi!
    i'm passing an array of arrays from java applet using
    JSObject.getWindow(applet).call("jsFunction", array(array(), array()) );
    in every other browser than safari 4.0.2 it's no problem to iterate over this array. in safari "array.length" is undefined. is such construction supported in safari's js engine?
    Message was edited by: quaintpl
    Message was edited by: quaintpl
    Message was edited by: quaintpl
    Message was edited by: quaintpl
    Message was edited by: quaintpl

    Thanks for the answer but the problem is the type of object of method and how from pl/sql is posiblle to call.
    The method waiting a ArrayofAlicIva, but if i define this object is not posible to set the object inside the array because the wsdl not have this functions.
    I need to define array of objects but the object is inside is the diferent type of array.
    If i Define the array of object correct to object inside, the method expect that the other array type.
    Is a Deadlock ??
    The solution in Java is Simple
    AlicIva[] alicIva = new AlicIva[1];
    alicIva[0]= new AlicIva();
    alicIva[0].setId(Short.parseShort(1));
    fedr[0].setIva(alicIva);
    this is the method imported in java class to form
    -- Method: setIva (LArrayOfAlicIva;)V
    PROCEDURE setIva(
    obj ORA_JAVA.JOBJECT,
    a0 ORA_JAVA.JOBJECT) IS
    BEGIN
    args := JNI.CREATE_ARG_LIST(1);
    JNI.ADD_OBJECT_ARG(args, a0, 'ArrayOfAlicIva');
    JNI.CALL_VOID_METHOD(FALSE, obj, 'FECAEDetRequest', 'setIva', '(LArrayOfAlicIva;)V', args);
    END;

Maybe you are looking for