A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Please help me understand the syntax.

  1. #1
    -i11.5Ki113D- jerryCLEMENT's Avatar
    Join Date
    Jan 2004
    Location
    Los Angeles, CA
    Posts
    248

    Please help me understand the syntax.

    EDIT - i have uploaded the basic .fla too if anyone wants to help show me using that.

    Hi,

    First let me apologize for the length of this post, but i am trying to explain clearly what my questions are. After searching for hours upon hours for a tutorial that doesn't invlove a seperate actionscript file, i have decided to dig through Adobe resource center and try to piece together the code myself and learn by doing what i am trying to accomplish. Since Adobe seems to have now made it a PITA for people who aren't developers to develop simple interactions within websites, i am going nuts trying to understand this basically new language.

    Coming from AS 2 (literally learned what i needed to get the job done (hey i'm a designer, not a developer) the way they changed the code is so confusing to me (to the point where i feel like i have never written actionscript at all).

    So i decided to make a simple circle on my stage. I turned it into a movieclip and gave it an instance name of testButton. What i am trying to learn is how to make a simple rollOver (which i guess is mouseOver now?) that will play the movieclip i am rolling over, then when rolled out of (mouseOut?) the movieclip goes to and plays the rollOut animation.

    Here is the code i was playing with.

    Code:
    stop();
    import flash.events.MouseEvent;
    testButton.addEventListener(MouseEvent:mouseOver, homeOver);
    function.homeOver(event.MouseEvent.mouseOver:void {
    				   testButton.gotoAndPlay(1);
    				   }
    When i tested the movie i got 5 code errors all in the way of syntax saying things like expecting ___ before dot or before colon, things like that. I am a patient person when it comes to learning new things, so i would appreciate any help that can be offered from you developer type people. Please understand that i am coding on the timeline and not in an actionscript file.

    My questions:

    1. using the import command - do i need to do this everytime i want an event in flash? lets say for this, i am trying to get a rollover (flash.events.MouseEvent). Is this the only event i will need to accomplish this?

    2. on the line where i have used the instance name (testButton) at the end of the line where i have defined homeOver, do i need to redefine homeOver for every other button but with a different name (contactOver, portfolioOver, etc, or can i use homeOver as well since i am describing a function that will basically be the same for every button?

    3.
    Code:
    function.homeOver(event.MouseEvent.mouseOver:void {
    				   testButton.gotoAndPlay(1);
    				   }
    help me understand what this line actually means (not in tech speak please). Is it "function.homeOver" is saying which function is being executed. Then in parenthesis "event.MouseEvent.mouseOver" is describing when the event happens? I'm not clear on what void means or what this part is for. Obviously the brackets is defining what will happen when the mouseOver happens. Can i put multiple commands into this? say if i wanted it to play and say something else to happen at the same time like a trace, can i put both commands in the area?

    4. What is the proper command to tell something to gotoAndPlay on mouseOver?

    5. For the mouseOut can i just add that function under this function or do i have to reimport flas.events.MouseEvents again for the rollOut?

    6. Whats the deal with packages? Is this something i will need to know for general interactivity on websites where i am coding on the timeline? Or is it for more advanced developement of Flash apps?

    7. Can i not put stop(); inside a movieclip anymore?

    I greatly appreciate any help on this. I have been building Flash sites as a designer for almost 3 years now and i feel like i am back at square one with AS3. I know i can still use AS2, but i came across a feature that will only be possible in AS3 so i really want to understand and learn how to do this since eventually AS2 won't be viable as Flash gets updated.
    Attached Files Attached Files
    Last edited by jerryCLEMENT; 06-24-2007 at 04:47 AM.

  2. #2
    -i11.5Ki113D- jerryCLEMENT's Avatar
    Join Date
    Jan 2004
    Location
    Los Angeles, CA
    Posts
    248
    yay, go go script assist.

    This is the final script that i got. Still curious about the questions i had though.

    Code:
    import flash.display.MovieClip;
    testButton.stop();
    testButton.addEventListener(MouseEvent.MOUSE_OVER, buttonOver);
    function buttonOver(e:MouseEvent):void {
    	testButton.play();
    }
    testButton.addEventListener(MouseEvent.MOUSE_OUT, buttonOut);
    function buttonOut(e:MouseEvent):void {
    	testButton.gotoAndPlay(11);
    	trace('roll out!');
    }
    testButton.addEventListener(MouseEvent.MOUSE_DOWN, buttonHit);
    function buttonHit(e:MouseEvent):void {
    	trace('hit!');
    }

  3. #3
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    The main problem is your syntax. AS3 is not so much different from AS2. You can compare the button script with a listener script of an AS2 component button.
    I would change one more thing inside the button scripts. Change
    testButton.gotoAndPlay(11); or play to
    e.target.gotoAndPlay(11);
    and
    e.target.play();

    By this way you refer from inside the function to the outside for the event.
    - The right of the People to create Flash movies shall not be infringed. -

  4. #4
    -i11.5Ki113D- jerryCLEMENT's Avatar
    Join Date
    Jan 2004
    Location
    Los Angeles, CA
    Posts
    248
    Will "e" ever change depending on the code? or does "e" just symbolize and event?

    Also if i am trying to target a movieclip inside a movieclip (like the other thread you were helping me with) would the targetting work the same in AS3? for example

    Code:
    e.navigation.home.gotoAndPlay(5);
    Like that? I know once i get more familiar with the functions, classes, and syntax ill pick it up a lot quicker, but right now i'm just learning by doing i guess. Probably better for me with the hands on approach anyway.
    Last edited by jerryCLEMENT; 06-24-2007 at 09:45 PM.

  5. #5
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You can write whatever you want. It is a parameter for event. e.target is referring to to the object, which induces the event, in this case testButton. So you always need to write e.target first.
    - The right of the People to create Flash movies shall not be infringed. -

  6. #6
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Quote Originally Posted by jerryCLEMENT
    1. using the import command - do i need to do this everytime i want an event in flash? lets say for this, i am trying to get a rollover (flash.events.MouseEvent). Is this the only event i will need to accomplish this?

    2. on the line where i have used the instance name (testButton) at the end of the line where i have defined homeOver, do i need to redefine homeOver for every other button but with a different name (contactOver, portfolioOver, etc, or can i use homeOver as well since i am describing a function that will basically be the same for every button?

    3. Is it "function.homeOver" is saying which function is being executed. Then in parenthesis "event.MouseEvent.mouseOver" is describing when the event happens? I'm not clear on what void means or what this part is for. Obviously the brackets is defining what will happen when the mouseOver happens. Can i put multiple commands into this? say if i wanted it to play and say something else to happen at the same time like a trace, can i put both commands in the area?

    4. What is the proper command to tell something to gotoAndPlay on mouseOver?

    5. For the mouseOut can i just add that function under this function or do i have to reimport flas.events.MouseEvents again for the rollOut?

    6. Whats the deal with packages? Is this something i will need to know for general interactivity on websites where i am coding on the timeline? Or is it for more advanced developement of Flash apps?

    7. Can i not put stop(); inside a movieclip anymore?
    1. No, actually you dont need to import events at all if you write code in the Flash. Flash will do it for you.

    2. You can use same functionn for every button.

    3.
    Code:
    function homeOver(e:MouseEvent):void {
    	   testButton.gotoAndPlay(1);
    }
    This is how you write functions.

    homeOver is name of function.

    e:MouseEvent is argument that is being passed to the function when it is called. In this case the argument is of type MouseEvent and the "e" is variable that gets assigned the value of mouse event.

    void means function is not returning anything.

    You can write as many lines inside the function as you like.

    4. There is no single command to "tell something to gotoAndPlay on mouseOver". You achieve it by adding listener to the object and defining function to react on mouseOver event. Which is what you have been doing...

    5. Look at 1 - you do not need to import events at all.

    6. Packages are used for external classes. If you write code in timeline inside Flash then you dont need them.

    7. Yes you can still use stop() command in timelines.

  7. #7
    -i11.5Ki113D- jerryCLEMENT's Avatar
    Join Date
    Jan 2004
    Location
    Los Angeles, CA
    Posts
    248
    Ok. I'm starting to pick this up a bit. While doing this i am trying to learn by getting a mouseOver to work on a movieclip that is inside another movieclip. It seems whenever i rollover the movieclip inside Flash acts like i am rolling out of the parent clip. Why is this? The inside button is on a layer right above the animation for the parent clip. Are layers just for show? Technically the clip would still be under it, but is just not visible. Flash will only recognize what we see and not what we see and everything below it?

    I have attached the file i have been working with. Just a simple movie clip, acting like a button, with another movie clip inside of it, trying to act like another button. Will this require some crazy code or is it something semi easy enough for someone to show me?

    Cancer - using e for the event before my play command "e.testButton.play();" causes errors to be given back at runtime. does it need to be e.testButton whenever testButton is referenced?

    Tony - thanks for the answers. It seems like AS3 isn't AS BAD as i thought when i started looking at tutorials and things. Never written AS in terms of development. Thanks for clearing it up.

    Also, thank you guys for your patience. It really is appreciated.
    Attached Files Attached Files
    Last edited by jerryCLEMENT; 06-25-2007 at 05:55 AM.

  8. #8
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    As I said already above, you cannot write e.testButton. You need to write e.target which will refer to the event target, which in your case is the testButton.

    In your example it is clear that your parent button will react when you go with the mouse over the childbutton, because the mouse is now leaving the parent button, which is equal to a MOUSE_UP event.
    - The right of the People to create Flash movies shall not be infringed. -

  9. #9
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    There is 2 problems:

    *the child mc (insideButton) somehow starts Mouse Over event too because its parent has it set
    *once the mouse goes ober insideButton, it is leaving testButton mc and so the MOUSE_OUT event activates

    Here I made it work somehow:
    Code:
    testButton.stop ();
    testButton.addEventListener (MouseEvent.MOUSE_OVER, buttonOver);
    function buttonOver (e:MouseEvent):void {
    	testButton.play ();
    	testButton.removeEventListener (MouseEvent.MOUSE_OVER, buttonOver);
    	testButton.addEventListener (MouseEvent.MOUSE_OUT, buttonOut);
    }
    function buttonOut (e:MouseEvent):void {
    	if (e.relatedObject==null || (e.target.name!="insideButton" && e.target.name!="testButton")) {
    		testButton.gotoAndPlay (11);
    		testButton.removeEventListener (MouseEvent.MOUSE_OUT, buttonOut);
    		testButton.addEventListener (MouseEvent.MOUSE_OVER, buttonOver);
    	}
    }

  10. #10
    -i11.5Ki113D- jerryCLEMENT's Avatar
    Join Date
    Jan 2004
    Location
    Los Angeles, CA
    Posts
    248
    So this code is basically removing the listener for the mouseOut when the insideButton is rolled over?

    Sorry for my noobism.

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