Help with buttons loading sections. Code looks awkward!

Hi everyone!
I have a class that creates a navBar with some buttons. Each button loads an external .swf and everything is working just fine BUT the code is really awkward. I also wanted to use TweenLite to add transitions from section to section.
I also wanted to handle the "section change" process from yet another Class (SectionChange) but whenever I try it I fail miserably.
Here's what I have (including the vars), without the SectionChange Class, that's working.
private var _app:Sprite;
private var _navData:Array;
private var _loader:LoadDisplayObject;
private var _container:Sprite = new Sprite();
private var _currentSection:String = "";
public function NavBar(app:Sprite, navData:Array) {
     _app = app;
     _navData = navData;
     _navData.pop();
     addChild(_container);
     build();
private function build():void {
     for (var i:uint;i < _navData.length;i++) {
          var menuBtn:MenuBtn = new MenuBtn(_navData[i]);
          menuBtn.name = _navData[i];
          menuBtn.x = 420 + (menuBtn.width + 3) * i;
          menuBtn.y = 60;
          menuBtn.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
          addChild(menuBtn);
private function onClick(e:MouseEvent):void {
     if (_currentSection == e.target.name + ".swf") {
          trace("Section Already Loaded");
     } else {
          _currentSection = e.target.name + ".swf";
          _loader = new LoadDisplayObject(_currentSection);
          _loader.addEventListener("displayObjectLoaded", checkChildrenNum, false, 0, true);
          _container.addChild(_loader);
          trace("Another Section were Loaded");
private function checkChildrenNum(e:Event):void {
     if (_container.numChildren > 1) {
          _container.removeChildAt(0);
As I said, this is working, but it's going to be a mess when I start adding the Tweens.
So here is the same code now using the SectionChange class that I tryed to implement.
//Inside NavBar class (same as above)
private function onClick(e:MouseEvent):void {
//edit: ADDING THE _sectionChange TO THE DISPLAY LIST HELPS A LOT WITH THE ERRORS and returns only one error.
     addChild(_sectionChange);
     _sectionChange = new SectionChange(e.target.name + ".swf");
And here's the SectionChange class:
public class SectionChange extends Sprite {
     private var _loader:LoadDisplayObject;
     private var _container:Sprite = new Sprite();
     private var _currentSection:String = "";
     public function SectionChange(currentSection:String = "") {
          if (_currentSection == currentSection) {
               trace("Section Already Loaded");
          } else {
               _currentSection = currentSection;
               _loader = new LoadDisplayObject(_currentSection);
               _loader.addEventListener("displayObjectLoaded", checkChildrenNum, false, 0, true);
               _container.addChild(_loader);
               trace("Another Section were Loaded");
     private function checkChildrenNum(e:Event):void {
          if (_container.numChildren > 1) {
               _container.removeChildAt(0);
I don't know what I'm doing wrong here but I get tons of errors with this code.
edit: Now that I'm adding the _sectionChange to the display list I only get the following error:
TypeError: Error #2007: Parameter child must be non-null.
    at flash.display::DisplayObjectContainer/addChild()
    at br.com.publishyours::NavBar/onClick()
Thanks again for all the patience!
Message was edited by: newToAS3

I finaly understood the error and got the SectionChange to work.

Similar Messages

  • Help with buttons :S

    hi all,
    i'm new to flash but i have an idea whats going on with webpages. I need some help with buttons! i have a website and its has a stage and 9 different flv's (screens). I've been trying to read online and i can't find out how to navigate to different screens, example below
    home          |            |
    about us     |  stage   |
    contact       |            |
    you click one one button it updates the stage. also i'm using actionscript 2.0.
    thanks for any help ahead of time
    Thank you,

    Is it a wi-fi or cellular connection that isn't working?  If its wi-fi and other people/computers/phones can connect check your settings.  If its cellular, are other people's phones (on the same carrier) working in the same location? If other people can't connect then it is likely a network problem.  If others can you may need to reset/restore you iPhone.

  • Looking for help with movie loading in a different spot every time page reloads.

    Hello,
    I have a Flash movie that I need to jump to a one of 6 chosen frames when say a user hits the back button or home in the site. I just dont want the same user seeing the flash movie replay in the same spot everytime they go back to home.
    ANY help with this is appreciated.
    Thanks ahead of time.
    -Ann
    Here is what I have scripted:
    var numbers:Array = [2,114,415,687,960,1195,1485];
    _root.firstTime = true;
    if(firstTime) {
        firstTime = false;
        var frame:Number = Math.floor(Math.random() * numbers.Length);
        gotoAndPlay(numbers[frame]);
    I have also tried this:
    Array.prototype.shuffle = function() {
    for (var ivar = this.length-1; ivar>=0; ivar--) {
    var p = random(ivar+1);
    var t = this[ivar];
    this[ivar] = this[p];
    this[p] = t;
    ASSetPropFlags(Array.prototype, ["shuffle"], 1, 1);
    var Array_ar:Array = new Array(2,114,415,687,960,1195,1485);
    Array_ar.shuffle();
    index = 0;
    function load_random() {
    gotoAndPlay(Array_ar[index++]);
    if (index == Array_ar.length) {
    (index=0);
    load_random();
    But this keep jumping to frame 1 each time i hit back or refresh.
    Thanks again.

    That did not work. It loops back to the frame that it first loaded to not to frame 1 the beginning.
    It tried putting gotoAndPlay(numbers[frame]); on the very last frame, then I made a new keyframe after the very last frame and neither worked.
    You can see the swf here:
    http://www.shared-vision.net/testsites/edi/EDIflashtest2.html
    Thank you for your help.
    -Ann

  • Help with buttons accessing loaded layers

    Hi all...Using Flash CS3 and AS3 to build a learning module that will load different layers of SWF files based on buttons on the main screen.  Got this working with no problems.  What I want to do is add buttons to provide learners some functionality, specifically a forward button, back button and a check box that will keep advancing automatically.  I've done massive searches and so far nothing seems to work.  Seems like what I am acccessing so far is the main layer, not the new layers as they are loaded.  Below is what I have been trying with the back button; the foward button uses nextFrame and is Handler2.  It isn't working.  Not even sure how to start with the checkbox for auto advance.  Any help would be GREATLY appreciated.
    Mark
    back_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler1);
    function mouseDownHandler1(event:MouseEvent):void
                    MovieClip(root).prevFrame();

    Thank you for your reply.  This is what I have so far - the module has four differentSWFs that load depending on what the user selects.  The modules are titled Introduction, Standards, Elements, and Traits.  When clicked, the button loads that specfic SWF and the previous one is unloaded. Hope I am using the correct terminology - I'm more familiar with AS2 than 3!

  • Help with button code please?

    I am a novice and have just completed my first animated movie. I need help with action script.
    The movie is currently looped and I have created and invisible button the size of the frame with the intention that a user can click on the movie image to stop it and on second click continue the movie from where it stopped.
    I have used the AS event handler method to stop the movie. I have tested it and it works. But I cannot figure suitable code to restart the movie.
    Two questions;
    1. am I going about the task the right way? (should I use two buttons, one stop, one start)?
    2. if my approach is feasible, can anyone give me the correct AS to re-start the movie and put me out of my misery please?

    you can use the following after changing "yourbutton" and "yourmovieclip" to use suitable instance names:
    yourbutton.onRelease=function(){
    if(!this.toggle){
    yourmovieclip.stop();
    } else {
    yourmovieclip.play();
    this.toggle=!this.toggle;

  • Help with java digital signing code

    hello people.
    can anybody help me?
    i have find a java code to resolve my problem with sending pay in soap envelope with digital signature and attached certificate. i compiled it with jdk jdk1.6.0_37. and it works.
    i need it to work in built-in jvm in oracle 9i. in oracle 9i jvm release is 1.3.1. Java code does not work there. there is an error
    class import com.sun.org.apache.xerces.internal.impl.dv.util.Base64 not found in import.
    i did not find this class in network.
    can anybody help with rewriting it for jvm 1.3.1?
    thanks in advance.
    code below:
    import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
    import java.io.*;
    import java.security.Key;
    import java.security.KeyStore;
    import java.security.PrivateKey;
    import java.security.Signature;
    import java.security.cert.Certificate;
    public class Sign {
    public static void main(String[] args) throws Exception {
    // TODO code application logic here
    BufferedReader reader = new BufferedReader(new FileReader("c:\\cert.p12"));
    StringBuilder fullText = new StringBuilder();
    String line = reader.readLine();
    while (line != null) {
    fullText.append(line);
    line = reader.readLine();
    KeyStore p12 = KeyStore.getInstance("pkcs12");
    p12.load(new FileInputStream("c:\\cert.p12"), "Hfrtnf$5".toCharArray());
    //????????? ????????? ????, ??? ????? ????? ???????????? alias ? ??????
    //Key key = p12.getKey("my kkb key", "ryba-mech".toCharArray());
    Key key = (Key) p12.getKey("my kkb key", "Hfrtnf$5".toCharArray());
    Certificate userCert = (Certificate) p12.getCertificate("my kkb key");
    String base64Cert = new String(Base64.encode(userCert.getEncoded()));
    //signing
    Signature signer = Signature.getInstance("SHA1withRSA");
    signer.initSign((PrivateKey) key);
    signer.update(fullText.toString().getBytes());
    byte[] digitalSignature = signer.sign();
    String base64sign = new String(Base64.encode(digitalSignature));
    String base64Xml = new String(Base64.encode(fullText.toString().getBytes()));
    System.out.println("<certificate>" + base64Cert+"</certificate>");
    System.out.println("<xmlBody>" + base64Xml+"</xmlBody>");
    System.out.println("<signature>" + base64sign+"</signature>");
    Edited by: user13622283 on 22.01.2013 22:08

    My first search is to see if there is an Apache commons project that provides it. Lo and behold:
    http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Base64.html
    commons-codec.

  • HELP WITH AN OLDER VERSION CODE!!!!!

    I am trying to figure out how to convert a code from an older version into JDK1.3.1_01.
    Please HELP!
    Here is my code............
    mport java.awt.*;
    import java.applet.*;
    public class Race extends Applet {
    private Button myButton; //use a button to start the race.
    int race_square; //record the race square 70.
    int t_square; //record the tortoise's position.
    int h_square; //record the hare's position.
    int clock; //record clock ticks.
    public void init()
    myButton=new Button("Start Clock") ; //add button to the top of panel.
    add("North",myButton);
    reset_v();
    public void reset_v()
    race_square=70; // total squares is 70
    t_square=1; //start point =1
    h_square=1; //start point=1
    clock=0; //reset the clock to zero.
    public void race() {
    int i=0; //set some integer varibles.
    int t_random=0; //random number for tortoise.
    int h_random=0; //random number for hare.
    Graphics g=getGraphics(); //define graphics.
    Rectangle r = bounds(); //define painting boundary.
    g.drawString("BANG !!!!!",100,r.height/2-80);
    g.drawString("AND THEY'RE OFF !!!!!",100,r.height/2-70);
    g.drawString(Integer.toString(clock),r.width/2,50); //show the zero clock time.
    do{
    try { Thread.sleep(1000);} //clock ticks 1 second.
    catch (InterruptedException e){}
    clock++;
    g.setColor(Color.lightGray); //clear all the old drawings
    g.fillRect(0,0,r.width,r.height);
    g.setColor(Color.black);
    g.drawString(Integer.toString(clock),r.width/2,50); //show the clock time.
    t_random=getrandom(); // FOR TORTOISE
    if (t_random<=5) t_square+=3; // 50% fast plod: 3 squares to the right.
    else if (t_random>5 && t_random<=7)t_square-=6; // 20% slip: 6 squares to the left.
    else t_square+=1; // 30% slow plod: 1 square to the right.
    h_random=getrandom(); //FOR HARE
    if (h_random<=2) {} // 20% sleep: not move at all.
    else if (h_random>2 && h_random<=4)h_square+=9;// 20% big hop: 9 squares to the right.
    else if (h_random==5) h_square-=12; // 10% big slip: 12 squares to the left.
    else if (h_random>5 && h_random<=8)h_square+=1;// 30% slow hop: 1 square to the right.
    else h_square-=2; // 20% small slip: 2 aquares to the left.
    if(t_square<=0) t_square=1; //always start from 1.
    if(t_square>race_square)t_square=race_square;
    if(h_square<=0) h_square=1; //always start from 1.
    if(h_square>race_square)h_square=race_square;
    g.setColor(Color.red); //draw the tortoise's path: use red color.
    g.fillRect(5,r.height/2-5,5*t_square,5);
    g.drawString("T",5*t_square,r.height/2-7);
    g.setColor(Color.blue); //draw the hare path: use blue color.
    g.fillRect(5,r.height/2+1,5*h_square,5);
    g.drawString("H",5*h_square,r.height/2+17);
    g.setColor(Color.black); //draw the race squares.
    g.drawLine(5,r.height/2,5+5*race_square,r.height/2);
    for(i=5;i<=5+5*race_square;i+=5)
    g.drawLine(i,r.height/2-5,i,r.height/2+5);
    if (t_square==h_square &&t_square!=race_square) // tortoise bites the hare.
    g.drawString("OUCH!!!",5+5*h_square,r.height/2-16);
    }while ( t_square=race_square && h_square=race_square && t_square<=5+5*race_square;i+=5)
    g.drawLine(i,r.height/2-5,i,r.height/2+5);
    g.drawString("T",5,r.height/2-7); //mark tortoise
    g.drawString("H",5,r.height/2+17); //mark hare
    public int getrandom()
    return( 1+(int)(Math.random()*10)); // generating the random number 1 to 10.
    public boolean action(Event e, Object arg)
    if (e.target instanceof Button)
    reset_v(); //reset the initial variables.
    race(); //use the button the start the race.
    return true;

    You posted this yesterday, at
    http://forum.java.sun.com/thread.jsp?forum=54&thread=185330
    The code you've posted doesn't seem to include Ilikejava's suggested changes - which are, as far as I can tell, the major changes required to bring your applet in line with Java 1.3.
    It will be easier to help if you show what is wrong with your code, if it's generating a compiler error message or throwing an exception.
    Regards,
    -Troy

  • Query Help with Item Master & Warehouse Code

    Forum,
    I would like help with a query to identify any items within a database where a particular warehouse code does NOT exist against it. At present I have the following:
    select T0.ItemCode, T1.WhsCode from OITM T0
    INNER JOIN OITW T1 on T0.ItemCode = T1.ItemCode
    where T0.ItemCode NOT IN ('WHS1')
    This is returning all other instance and not just a list of item codes where 'WHS1' is missing from within the 'Stock Data' tab.
    Thanks,
    Sarah

    Hi Sarah...
    Try This
    SELECT T0.ItemCode, T0.ItemName, T1.WhsCode
    FROM OITM T0 INNER JOIN OITW T1 ON T0.ItemCode = T1.ItemCode
    WHERE T1.WhsCode not in ( 'WHS1')
    Regards
    Kennedy

  • Need help with SQL*Loader not working

    Hi all,
    I am trying to run SQL*Loader on Oracle 10g UNIX platform (Red Hat Linux) with below command:
    sqlldr userid='ldm/password' control=issue.ctl bad=issue.bad discard=issue.txt direct=true log=issue.log
    And get below errors:
    SQL*Loader-128: unable to begin a session
    ORA-01034: ORACLE not available
    ORA-27101: shared memory realm does not exist
    Linux-x86_64 Error: 2: No such file or directory
    Can anyone help me out with this problem that I am having with SQL*Loader? Thanks!
    Ben Prusinski

    Hi Frank,
    More progress, I exported the ORACLE_SID and tried again but now have new errors! We are trying to load an Excel CSV file into a new table on our Oracle 10g database. I created the new table in Oracle and loaded with SQL*Loader with below problems.
    $ export ORACLE_SID=PROD
    $ sqlldr 'ldm/password@PROD' control=prod.ctl log=issue.log bad=bad.log discard=discard.log
    SQL*Loader: Release 10.2.0.1.0 - Production on Tue May 23 11:04:28 2006
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    SQL*Loader: Release 10.2.0.1.0 - Production on Tue May 23 11:04:28 2006
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Control File: prod.ctl
    Data File: prod.csv
    Bad File: bad.log
    Discard File: discard.log
    (Allow all discards)
    Number to load: ALL
    Number to skip: 0
    Errors allowed: 50
    Bind array: 64 rows, maximum of 256000 bytes
    Continuation: none specified
    Path used: Conventional
    Table TESTLD, loaded from every logical record.
    Insert option in effect for this table: REPLACE
    Column Name Position Len Term Encl Datatype
    ISSUE_KEY FIRST * , CHARACTER
    TIME_DIM_KEY NEXT * , CHARACTER
    PRODUCT_CATEGORY_KEY NEXT * , CHARACTER
    PRODUCT_KEY NEXT * , CHARACTER
    SALES_CHANNEL_DIM_KEY NEXT * , CHARACTER
    TIME_OF_DAY_DIM_KEY NEXT * , CHARACTER
    ACCOUNT_DIM_KEY NEXT * , CHARACTER
    ESN_KEY NEXT * , CHARACTER
    DISCOUNT_DIM_KEY NEXT * , CHARACTER
    INVOICE_NUMBER NEXT * , CHARACTER
    ISSUE_QTY NEXT * , CHARACTER
    GROSS_PRICE NEXT * , CHARACTER
    DISCOUNT_AMT NEXT * , CHARACTER
    NET_PRICE NEXT * , CHARACTER
    COST NEXT * , CHARACTER
    SALES_GEOGRAPHY_DIM_KEY NEXT * , CHARACTER
    value used for ROWS parameter changed from 64 to 62
    Record 1: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 2: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 3: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 4: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 5: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 6: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 7: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 8: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 9: Rejected - Error on table ISSUE_FACT_TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 10: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 11: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 12: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 13: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 14: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 15: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 16: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 17: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 18: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 19: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 20: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 21: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 22: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 23: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 24: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 39: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    MAXIMUM ERROR COUNT EXCEEDED - Above statistics reflect partial run.
    Table TESTLD:
    0 Rows successfully loaded.
    51 Rows not loaded due to data errors.
    0 Rows not loaded because all WHEN clauses were failed.
    0 Rows not loaded because all fields were null.
    Space allocated for bind array: 255936 bytes(62 rows)
    Read buffer bytes: 1048576
    Total logical records skipped: 0
    Total logical records read: 51
    Total logical records rejected: 51
    Total logical records discarded: 0
    Run began on Tue May 23 11:04:28 2006
    Run ended on Tue May 23 11:04:28 2006
    Elapsed time was: 00:00:00.14
    CPU time was: 00:00:00.01
    [oracle@casanbdb11 sql_loader]$
    Here is the control file:
    LOAD DATA
    INFILE issue_fact.csv
    REPLACE
    INTO TABLE TESTLD
    FIELDS TERMINATED BY ','
    ISSUE_KEY,
    TIME_DIM_KEY,
    PRODUCT_CATEGORY_KEY,
    PRODUCT_KEY,
    SALES_CHANNEL_DIM_KEY,
    TIME_OF_DAY_DIM_KEY,
    ACCOUNT_DIM_KEY,
    ESN_KEY,
    DISCOUNT_DIM_KEY,
    INVOICE_NUMBER,
    ISSUE_QTY,
    GROSS_PRICE,
    DISCOUNT_AMT,
    NET_PRICE,
    COST,
    SALES_GEOGRAPHY_DIM_KEY
    )

  • Help with data load model

    Hi,
    I need help with a data load model. First, i'm doing delta extraction from R/3, we load data with a InfoSource to InfoCube A and InfoCube B.
    I'm doing master data validation on the load, so if a load fails for InfoCube A, it fails for InfoCube B too (this is because i can have only 1 InfoPackage for the 2 infocubes, because of the delta update).
    So i propose a new model in wich:
    - The delta load is taked first to an ODS.
    - ODS is cleaned before the delta update.
    - Then i create 2 InfoPackages for full load from ODS to  Infocube A, and from ODS to InfoCube B.
    With this solution i can have 2 infopackages from ODS because i'm not doing a delta load from here to the cubes, and with 2 infopackages i can have independent validations for each cube so if one of them fails, the other can still be loaded sucessfully.
    The solution fails because if i load delta from R/3 to the ODS i can't clean it first. The initialization and the old updates needs to be previuslly loaded on the ODS. Then i can't do full load to the cubes and neither have 2 infopackages.
    Please help me to solve this issue.
    thanks a lot

    Hi jeremy,
    what about this simple solution:
    load data by delta from R/3 in your ODS. You can also have an ODS/cube for the historical data which is more space-saving than holding all the old data in PSA. Then you load your historical data from PSA into the historical ODS/cube.
    From your ODS with the actual data you update your requests by full from ODS into the cubes with 2 different full infopackages. But because you load by full you have to use deletion selections in the infopackages to avoid duplicate data!
    regards,
    Jürgen

  • Help with some java login code

    hey,
    I am a new member but used to visit the site regularly. I am undergoing a java project and I cannot seem to get my head around how to code when users log in, there name must appear at the top of each page they visit.
    User enters name into a text box. Do I use getter and setter methods? any bit of help would be of some advantage to me.
    Thanks for your time and I'll help with anyone else who is stuck.

    if JSP or servlet use Session...
    if you are using frame you have to consider... which frame is a top parent. that top frame will have the set and get method.. for you to set and retrieve the user name.. bear in mind that different object will have different user...
    so you have to play fair game ...hehehehe :-)

  • Need help with this Pascal Triangle code....

    Hey everyonr i am totally new to Java... so need your help with this code...
    the function makeRows gives me problems... main is correct ... can someone fix my makeRows... i don't see what's wrong
    public class Pascal {
      /** Return ragged array containing the first nRows rows of Pascal's
       *  triangle.
      public static int[][] makeRows(int nRows) {
            int[][] mpr  = new int[nRows+1][];
            int l=0; int r=0;
            for (int row = 0; row < nRows; row++) {
              mpr[row] = new int[row+1];  //index starts at 0
              if (row==0) {
                mpr[0][0]= 1;
                    if (row==1) {
                mpr[1][0]= 1;
                mpr[1][1]= 1;
              if (row>=2) {
                 for (int j = 0; j <= row; j++) {
                    if (j==0)               {l=0;} else {l=mpr[row-1][j-1];}
                    if (j==mpr[row].length-1) {r=0;} else{r=mpr[row-1][j];}
                    mpr[row][j] = l + r;
            return mpr;
      public static void main(String[] args) {
             if (args.length != 1) {
               System.out.println("usage: java " + Pascal.class.getName() + " N_ROWS");
               System.exit(1);
             int nRows = Integer.parseInt(args[0]);
             if (nRows > 0) {
               int[][] pascal = makeRows(nRows);
               for (int[] row : pascal) {
              for (int v : row) System.out.print(v + " ");
              System.out.println("");
         }this makeRows function should return ragged array containing the first nRows rows of Pascal's triangle
    thanks
    Edited by: magic101 on May 9, 2008 4:03 PM

    magic,
    i think corlettk meant that some people might not know what pascal's triangle is.
    also, you didnt say what was wrong with your code, just that it was wrong.
    asking smart questions is about giving as much information you can to get the
    best answer. i would throw a System.out.print between every line of your
    algorithm. i would also supply us with the values you are getting for each row.
    also, this question is asked all the time here. do a forum search.
    1
    11
    121
    1331
    14641

  • Help with understanding multi-threaded code

    Hi Everyone,
    I am currently reading a book on multi-threading and up until recently I have been able to understand what is going on. The thing is the complexity of the code has just jumped up about two gears without warning. The code is now using inner classes which I am trying to develop an understanding of but I am not finding it easy going, and the book has been lite on explanations. If anybody can help with the following code it will be really appreciated.
    public class SetPriority extends Object
         private static Runnable makeRunnable()
              Runnable r = new Runnable()
                   public void run()
                        for(int i=0; i<5; i++)
                             Thread t = Thread.currentThread();
                             System.out.println("in run() - priority=" + t.getPriority() +
                                          ", name=" + t.getName());
                             try{
                                  Thread.sleep(2000);
                             }catch(InterruptedException x){
                                  //ignore
              return r;
         public static void main(String[] args)
              Thread threadA = new Thread(makeRunnable(), "threadA");
              threadA.setPriority(8);
              threadA.start();
              Thread threadB = new Thread(makeRunnable(), "threadB");
              threadB.setPriority(2);
              threadB.start();
              Runnable r = new Runnable()
                   public void run()
                        Thread threadC = new Thread(makeRunnable(), "threadC");
                        threadC.start();
              Thread threadD = new Thread(r, "threadD");
              threadD.setPriority(7);
              threadD.start();
              try{
                   Thread.sleep(3000);
              }catch(InterruptedException x){
                   //ignore
              threadA.setPriority(3);
              System.out.println("in main() - threadA.getPriority()=" + threadA.getPriority());
    }My greatest challenge is understanding how the makeRunnable() method works. I don't understand how this inner class can be declared static and then multiple "instances" created from it. I know that I have no idea what is going on, please help!!!
    Thanks for your time.
    Regards
    Davo
    P.S.: If you know of any really good references on inner classes, particularly URL resources, please let me know. Thanks again.

    Yikes!! The good news is that you're unlikely to see such convoluted code in real life. But here we go.
    "private static Runnable makeRunnable()" declares a method that returns objects of type Runnable. The fact that the method is declared "static" is pretty irrelevant - I'll describe what that means later.
    The body of the method creates and returns an object of type Runnable. Not much special about it, except that you can give such an object to the constructor of class Thread and as a result the run() method of this Runnable object will be called on a new thread of execution (think - in parallel).
    Now the way it creates this Runnable object is by using the "anonymous inner class" syntax. In effect the method is doing the same as
    public class MyNewClass implements Runnable {
        public void run() {
            // All the same code inside run()
    public class SetPriority {
        private static Runnable makeRunnable() {
            Runnable r = new MyNewClass();
            return r;
        // The rest of the original code
    }Except you don't bother declaring MyNewClass. You're not interested in defining any new method signatures. You just want to create an object that implements Runnable and has certain instructions that you want inside the run() method. Think of the whole approach as shorthand.
    Think about this for a while. In the mean time I'll write up the "static".

  • Elasticity: help with converting Flash 5 code to Flash 8

    Hello
    because I have to make a flash menu with elasticity effect I
    came upon this tutorial:
    http://www.kirupa.com/developer/actionscript/spring.htm
    All OK but the code there works only with Flash 5. I somehow
    managed to concoct code that works for Flash 6 but still I didn't
    come even close to a code working in Flash 8. I'm using
    Actionscript only from version 7, I do not know anything about
    Flash 5 and 6. So please, the more experienced guys, help me!!
    The code I concocted is:
    MovieClip.prototype.move = function (centerx, centery,
    inertia, k) {
    this.x = -this._x+centerx;
    this.y = -this._y+centery;
    this.xp = this.xp*inertia+this.x*k;
    this.yp = this.yp*inertia+this.y*k;
    this._x += this.xp;
    this._y += this.yp;
    onEnterFrame=function() {
    this.move (_root._xmouse,_root._ymouse,0.9,0.1) ;
    This whole code is on the timeline of the MC being moved.
    So now the only thing I need is to make this code work for
    Flash 8
    Please, help

    Just managed to do it !

  • Help with buttons

    Hey all,
    I'm new here, and new to Java. I am trying to create a beetle drive game that allows players to play against three other players or computer players. I want to use buttons to allow the players to choose which player is playing. I have got the buttons in my code, but i don't know how to get them to change players and go to the appropriate beelte drawing. Any halp on this would be greatly appreciated.
    If the code is needed, let me know an i will email it.
    Cheers

    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    public class beetle extends Applet implements ActionListener{
        Font f=new Font ("Comic Sans", Font.ITALIC, 14);
        private Button throwDice;               //Dice button
        private boolean thrown = false;
        private int eyeCounter = 0;
        private int legCounter = 0;
        private int feelerCounter = 0;          //declare all variables
        private int ScoreCounter = 0;
        private int die1 = 0;
        public int tail = 0;
        public int body = 0;
        public int head = 0;
        public boolean endGame = false;
        private MyCanvas canvas = new MyCanvas();
        private Button one = new Button("One");
        private Button two = new Button("Two");
        private TextField display = new TextField(20);
        public void init() {
            canvas.setBackground(Color.yellow);
                canvas.setSize(545,400);
                add(canvas);
            throwDice = new Button("Throw");
            add(throwDice);
            throwDice.addActionListener(this);
            add(one);
            one.addActionListener(this);
            add(two);
            two.addActionListener(this);
            add(display);
        public void actionPerformed(ActionEvent event)  {
            thrown = true;
            canvas.repaint();
              if (event.getSource() == one)
                display.setText("Player One is Playing");
            else
                display.setText("Player Two is Playing");
        This is what i have got for the two buttons that i have got at the minute. Currently, when i press one a player button, it throws the die for me again. I need it to switch to that players drawing of the beetle.

Maybe you are looking for

  • Newbie needs help!  Cannot open database home page...

    Hi all, I know this sort of question has been posted before but either it never got resolved or the thread seems to just die... I have just installed 10gXE and have tried to open the 'homepage' but all I get is 'page not available' errors in either I

  • An interesting problem for HP All-in-one machines

    I posted a problem Sunday about my system freezing during boot. It was suggested that my power supply was probably underpowered. See link below for the thread: https://forum-en.msi.com/index.php?threadid=43996&sid= I bought a new 480W power supply (s

  • Migrating from older macs to a new powerbook G4

    I've got one of the new powerbooks ordered and on the way, and I'm very excited about it -- improved resolution, all that screen space, tons of RAM, 1.67 mghz -- YAHOO. But I'm also dreading the moving part. Right now I've got a desktop G4 desktop im

  • Kernel Panics when waking from sleep? 2012 MBA Base Model

    I've been having some trouble with my 2012 MacBook Air. It was running perfectly until about 2 weeks ago. Now, when waking from sleep, I am getting Kernel Panics that force the restart of my Mac. I was wondering if anyone could provide insight on the

  • Wanted: A contact manager/address book with a sense of time

    There is one feature which I didn't find in any contact management application out there, and which keeps me using paper-based solutions: A way to see how old old any specific piece of information is. Use case: „This phone number of X I wrote down/sa