Flash Advisor logo
:: Desktop Shortcut
:: Flash Help
Advice from Experts

Closed Thread
Results 1 to 6 of 6
  1. #1

    Default Calculation In Button Click event

    Can someone please help me with this? I am new to Flash Action Scripting.
    I need to take a dynamic value from the text box field which user will enter at runtime, take that value and divide this value by 6 and return this value in another text box in a button click event.

    I have written this script but it gives me 3 errors.

    butcalculate.onPress = Function cal()
    {Set Variable: "i"= earthWeight.text;
    Set Variable: "x"= i/6;
    this.moonWeight.text=x}

    Thank you

  2. # ADS
    Join Date
    Always
    Posts
    Many
     
  3. #2
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    Maybe something like......

    Code:
    earthWeight.text = "Input earth weight";
    earthWeight.onSetFocus = function() {
    	earthWeight.text = "";
    }
    butcalculate.onPress = function() {
    	var i = earthWeight.text;
    	var x = i/6;
    	_root.moonWeight.text = Math.round(x);
    }
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

  4. #3

    Default It gives me 3 errors...

    I tried your solution NTD, but it gives me 3 errors and also it says not suppoted by Flash 5, even though i am working in Flash MX. I pasted your code in the Action Panel for the button. It gives me following errors :

    WARNING: This movie uses features that are not supported in the Flash 5 player
    Scene=Scene 1, layer=field: moonWeight, frame=1:Flash MX Text Field Instance Name
    Scene=Scene 1, layer=field:earthWeight, frame=1:Flash MX Text Field Instance Name
    **Error** Scene=Scene 1, layer=button:calc, frame=1:Line 1: Statement must appear within on handler
    earthWeight.text = "Input earth weight";

    **Error** Scene=Scene 1, layer=button:calc, frame=1:Line 2: Statement must appear within on handler
    earthWeight.onSetFocus = function() {

    **Error** Scene=Scene 1, layer=button:calc, frame=1:Line 5: Statement must appear within on handler
    butcalculate.onPress = function() {

    Scene=Scene 1, layer=button:calc, frame=1:Flash MX Button Instance Name
    Total ActionScript Errors: 3 Reported Errors: 3


    As i am new to flash Action scripting, can you please help me to sort this?

    Thank you !

  5. #4
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    I guess I should have asked which version of Flash you were using. I assumed you were using FlashMX or FlashMX2004. I have not coded anything for Flash5 in a long while. I have forgotten some of the limitations. I know Flash5 cant use button instance names and I dont think the "text" property of a textfield was introduced until FlashMX. Flash5 was also commonly used object code over frame code so the buttons would need the code instead of the frame. Hmmmm, maybe try something like this......

    Create two textfields and give them variable names of earthWeight and moonWeight. Create a button and paste this actionscript directly onto the button.....
    Code:
    on(press){
    i=earthWeight;
    x=i/6
    moonWeight=x;
    }
    Edit...... I guess I need to read more accuratly, you are apparently using FlashMX. What you need to do is export the movie as an .swf file and make sure your using the latest player version. Flash MX code wont work with player version 5...... only 6 and higher. I'll make a quick demo file and post it to my site.

    NTD
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

  6. #5
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    Here is a quick demo file in MX format using the original code sample. Change the .swf extension to .fla to download the file for a closer look.....

    http://ntdesigns.net/quickDemo/earthWeightDemo.swf

    Regards
    NTD
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

  7. #6

    Default Thank you

    Thank you NTD

    Your code works...
    Actually my mistake was, I was pasting your code in the action panel of the button ( like in flash 5). I am new to Flash MX, so I did not know that it has to be in the first frame of the movie. When I pasted it in the 1st frame it Works perfect.

    Thank you so much!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Replies: 2
    Last Post: 08-08-2008, 02:58 PM
  2. Button with movie click.. Dont quite understand
    By fstopeleven in forum General Flash
    Replies: 1
    Last Post: 04-25-2006, 10:46 PM
  3. Suddenly I have to click twice on my flash button
    By nivola in forum General Flash
    Replies: 6
    Last Post: 04-25-2006, 07:06 PM
  4. Button problem- click more than once
    By Kirbysmom in forum General Flash
    Replies: 4
    Last Post: 07-04-2005, 08:43 PM
  5. image fading to another on button click
    By liqidhed in forum Design and Animation
    Replies: 1
    Last Post: 06-01-2005, 05:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Sponsors
Create Speaking Characters for your website and Flash movies. 15 Day Free Trial