A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: If actionscript help needed!

  1. #1
    Junior Member
    Join Date
    Dec 2002
    Location
    Santa Maria, CA
    Posts
    13

    If actionscript help needed!

    K, guys this is my first post and let me tell you I am an extreme NooB to flash all together but I have alot of director and Html background.

    Ive been battling this script for bout a week now and decided to ask for help since i dont have access to any flash books that seem to have the awnsers i need.

    Here is in words what im trying to do:

    If Variable 1 plus Variable 2 plus Variable 3 are equal to or greater than 1 then set Variable 4 equal to Text String1

    Ive got about fifty different starts at this but none work so im not going to place my failed attempts at it here....if anyone is willing to play with this and figure it out or if its easy just post the script Id appreciate it much!

    Thanks,
    Croatoan

  2. #2
    Member
    Join Date
    Jun 2001
    Posts
    99

    Free tutorials

    First get some great free lessons at actionscript.org , really you'll learn alot pretty quickly.

    To help answer your question tell us what version of flash your using and what event is meant to trigger your script, are you sure you variables (1 - 3) are numbers and 4 is text?

    The actual calculation part is like basic algebra with syntax for AS:

    if((var1 + var2 + var3) >= 1){
    var4 = String1;
    }

    You'll need an event, say for a mouse button release or when the movie enters a certain frame.

    To have a clue with AS and get started:

    1. Know what a variable is.
    2. Know what an event is.
    3. Know what a button is (in detail).
    4. Know what a mouse is (as far as flash is concerned).

    Try the tutorials and you'll soon be asking 'why doesn't my function work?'.

    Good luck

  3. #3
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    I think the hardest part of flash is scoping. I started with director too and scoping really wasnt a problem there because you pretty much had 3 kinds of variables: local, global and properties and they are all easily accessed the same way, just using the variable name and sometimes sprite(spriteNum).variable.

    With Flash however, you have this whole deal of hierarchically arranged/embedded movieclips where if you are on the main timeline, to reference a movieclip within a couple of other movieclips you have to specify the path to reach that variable. ie. _root.mc1.mc2.variable. It sounds easy enough but when compouding that with the facts that you write scripts in all these locations, it starts off (and can continue to be) confusing. This especially with you being in one scope and adding script to a movieclip and a button within that scope and having each of those scripts reference seperate scopes themselves. Once you get this down though, (and the difference in syntax which is less verbose than Lingo but much easier to write once you know it) you should be able to get around in Flash quite easily.

  4. #4
    Junior Member
    Join Date
    Dec 2002
    Location
    Santa Maria, CA
    Posts
    13
    Okay sorry for the lack of detail:

    Im using Flash 5 currently.
    The script is a frame loaded script in the main movie (no submovies).

    I go into the script I need to complete with this script:

    loadVariablesNum ("alldata.txt", 0);
    available10x20 = "Currently Unavailable!";

    The loadVariablesNum is setting up my external editable variables and appears to be working properly so far. I also setup the variables that the script im working on will change the text for.

    Here is an excerpt of the alldata.txt file that pertains to the three variables im looking at and im pretty sure to awnser your last question that these are getting loaded as numbers:

    2W=1&2X=0&2Y=0&

    So im looking to add 2W, 2X, and 2Y and see if they total a value larger than 0 if they do i need to change the text of available10x20 to "Currently Available!"

    k that should be enough info if its not let me know, gonna go hit that site you said to check out right now thanks for the help so far guys.

    Thanks,
    Croatoan

  5. #5
    Junior Member
    Join Date
    Dec 2002
    Location
    Santa Maria, CA
    Posts
    13
    Here is actually what I got setup so far propabably not even close but its what i got:

    if((1A + 1B) >= 1){
    available10x20 = "Available!";
    }

    and when ever i hit Ctrl + Enter to preview the flash moview I get these errors out of my output window:

    Scene=Scene 1, Layer=ActionScripts, Frame=10: Line 1: ')' expected
    if((1A + 1B) >= 1){

    no matter what adjustments I make to the original script posted above I always end up with at least this error or worse.

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    variable names should NOT start with a number. Nor should they contain signs like + or -

    gparis

  7. #7
    Junior Member
    Join Date
    Dec 2002
    Location
    Santa Maria, CA
    Posts
    13
    Thanks Paris!!!!!!!

    Redid all 200 variabls of the full scope to switch numbers from first part of variable and whala no error in script no more....knew it was something simple and dumb.

    Thanks for all the help guys!

    Croatoan

  8. #8
    Junior Member
    Join Date
    Dec 2002
    Location
    Santa Maria, CA
    Posts
    13
    Grrrr.... I hate starting a new programming language =/ anyways....new problem....heres what i got so far....


    Variables A1 and B1 are loaded from alldata.txt in earlier script, test is a variable that is there only so i can use a dynamic text box to check the result of A1+B1....the problem is that if A1 = 1 and B1 = 1 .....test returns 1.....if A1 = 1 and B1 = 0.....test returns 1 but, if both are 0 then test returns 0.......A1 + B1 should return 2 if both are equal to 1.

    Am I not parsing variable correctly to convert the string Flash imports to a integer so i can perform my math?

    <-----------SCRIPT-------------->
    available10x20 = "Currently Unavailable!";
    Number (A1);
    Number (B1);
    test = (A1 + B1);
    if((A1 + B1) > "0" ){
    available10x20 = "Available Today!";
    }
    <----------END SCRIPT----------->

    Thanks again for any help,
    Croatoan

  9. #9
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    use parseInt(string)
    It will convert the string back to a number.
    If there are decimals use parseFloat(string)
    gparis

  10. #10
    Junior Member
    Join Date
    Dec 2002
    Location
    Santa Maria, CA
    Posts
    13
    Still the same problem returns value of first variable being added together in test variable. Also heres excerpt from my txt file.

    <---LLDATA.TXT EXCERPT--->
    &A1=1
    &B1=1
    <----END EXCERPT--->

    <-----------SCRIPT-------------->
    available10x20 = "Currently Unavailable!";
    parseInt(A1);
    parseInt(B1);
    test = (A1 + B1);
    if((A1 + B1) > "0" ){
    available10x20 = "Return 1";
    }
    <----------END SCRIPT----------->

    with current script test = 1 ???? should equal 2.....if i change A1 in txt file to 0 then.....test =0???? should equal 1 so I still got something funky somewhere.

    Croatoan

  11. #11
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    test = (parseInt(A1) + parseInt(B1));

    try that

    gparis

  12. #12
    Junior Member
    Join Date
    Dec 2002
    Location
    Santa Maria, CA
    Posts
    13
    You da man! Thanks again, fixed the problem. Makes since if parsing the variable to itself dont work parse it when you use it. =o) thanks.
    Croatoan

  13. #13
    Junior Member
    Join Date
    Dec 2002
    Location
    Santa Maria, CA
    Posts
    13
    Closing notes on this string here is the finishes script incase someone wants to do something similar and runs into the same problem:

    <---SCRIPT--->
    available10x20 = "Currently Unavailable!";
    BA10x20 = (parseInt(A1) + parseInt(B1)+ parseInt(D1)+ parseInt(E1)+ parseInt(N1)+ parseInt(O1));
    BB10x20 = (parseInt(B2) + parseInt(D2)+ parseInt(J2)+ parseInt(N2)+ parseInt(Q2)+ parseInt(W2)+ parseInt(X2)+ parseInt(Y2));
    check10x20 = (BA10x20 + BB10x20)
    if( check10x20 > "0" ){
    available10x20 = "Available Today!";
    }
    <---END SCRIPT--->

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center