A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Button Actionscript

  1. #1
    Registered User
    Join Date
    Feb 2006
    Location
    Canada
    Posts
    28

    Button Actionscript

    I am new to this so, It may be simple to some but not to me.

    I created a button it's instance name is "button1"

    This is the action script
    button1.onPress = function() {
    trace("test");
    }

    This is the error I get
    Scene=Scene 1, Layer=Layer 1, Frame=1: Line 1: Statement must appear within on handler
    button1.onPress = function() {

    What I tought would happen is that when I right click on the button, I would get a message "test"

    what am I doing wrong?

  2. #2
    village idiot BlackCow237's Avatar
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    192
    I just replicated what you told me and it worked fine for me. I get the out put, test. Make shure you are putting the action in frame one and not on the button. I think thats your problem. I dunno. Try redoing it, i did it in 2 seconds.
    Last edited by BlackCow237; 02-10-2006 at 03:46 PM.
    This is our world now, the world of the electron and the switch. We exist without nationality, skin color, or religious bias.

  3. #3
    Banned wbwd's Avatar
    Join Date
    Dec 2004
    Location
    Timisoara Country[EU]: Romania
    Posts
    860
    Yeps, works fine for me too... As BlackCow237 said, make sure that the actions is on the frame... Or maybe try to put the action on the same layer frame on which your button is ( sometimes that can occure too, but don't think that thats the prob here )...

  4. #4
    Registered User
    Join Date
    Feb 2006
    Location
    Canada
    Posts
    28
    Thanks guys that worked when I put the code in
    "Actions for Frame 1 of layer Name Layer 1" rather than "actions for button1"

    I don't understand why, shouldn't the action be for the button and not the frame ?

    What is the difference and when should you use

    on (press) {
    trace("Test");
    }

    instead of

    button1.onPress = function() {
    trace("test");
    }

    Ultimately I want to do this

    on (press) {
    duplicateMovieClip(_root.test1,_root.symbol 2,1);
    setProperty (test1, _x, random(275));
    setProperty (test1, _y, random(275));
    trace ("here I am");
    }

    when the user presses the button a copy of "symbol 2" is created at a random location.

    Can you point me in the right direction.

    thanks

  5. #5
    village idiot BlackCow237's Avatar
    Join Date
    Aug 2004
    Location
    Earth
    Posts
    192
    I could be wrong but im pritty shure that when you say on (press) it is on the button so you dont have to define its name and when you say button1.onPress it is on the main frame because you have to define the name of the button.
    This is our world now, the world of the electron and the switch. We exist without nationality, skin color, or religious bias.

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