Skip navigation
Bloom
Currently Being Moderated

Adding action script to instances...

Dec 25, 2008 3:31 PM

I'm pretty frustrated and am done searching the site. Awful...just awful. Anyway...

Using Flash CS3 for the first time since upgrading. I'm not able to add action script to instances. Certainly this isn't a change. I've created a button symbol. I've named the instance upon dragging it on the stage. Now it tells me I can't apply actions to it.

I hope I'm just missing a step.
 
Replies
  • Currently Being Moderated
    Dec 25, 2008 4:04 PM   in reply to Bloom
    How are you applying actions?
     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2008 4:07 PM   in reply to Bloom
    You're not missing anything. In AS3 with CS3 and CS4 this feature has been removed from Flash. Yes, it sucks.

    If you want to continue using AS3, you will need to give the button an instance name, and assign an action on the timeline which will look something like this:

    myButton.addEventListener('click',myButtonClick);
    function myButtonClick(event){
    // do stuff
    }

    Frankly, you probably want to just use AS2. You can set this in the publish settings or when creating a new document, choose the option which says "Flash File (ActionScript 2.0)"
     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2008 4:44 PM   in reply to Bloom
    Bloom, are you talking about writing actions INSIDE the symbols? If so - they went with a more robust approach of writing classes for the symbols. It takes not such a big effort to change the ways. In essence it is the same thing but gives one much bigger flexibility.

    Also, are you familiar with AS3 event model?
     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2008 4:59 PM   in reply to Bloom
    Andrei1, Bloom is not referring to class/symbol-definition code, but instance code. There is no IDE solution as of CS3 and CS4 for AS3.

    Bloom, are you sure the path is correct? Note that the path "playerMovies/hahnJordan09.swf" is relative to the embedding HTML page, not the swf.
     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2008 5:05 PM   in reply to Bloom
    I made the change in the path, but it's still not working. The code now reads:

    on (rollOver)
    {stageRoster.loadMovie("roster/2011/playerMovies/hahnJordan09.swf");
    }


    Here is the PHP page in question:

    http://spieceselect.org/roster/2011/index2.php

    Click on Jordan Hahn's name. It's the only one I've done so far.



     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2008 5:12 PM   in reply to Bloom
    As abeall said you need to indicate to CS3 that you use AS2

    When you refer to an instance in AS2 on the time line where the instance is
    you code should be:

    myButton.onRollOver = function()
    {stageRoster.loadMovie("playerMovies/hahnJordan09.swf");}



     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2008 5:12 PM   in reply to Bloom
    As abeall said you need to indicate to CS3 that you use AS2

    When you refer to an instance in AS2 on the time line where the instance is your code should be:

    myButton.onRollOver = function() {stageRoster.loadMovie("playerMovies/hahnJordan09.swf");}

    Your original code should work from withing the instance in AS2. But you will have to change reference to stageRoaster if it is located on the main timeline.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2008 5:24 PM   in reply to Bloom
    Bloom,

    I think you had it right the first time, I just didn't know where you had your files and it's a common misunderstanding. But the correct relative url should indeed be "playerMovies/hahnJordan09.swf"

    If you want to try an absolute url you can use "/roster/2011/playerMovies/hahnJordan09.swf"

    Are you sure stageRoster is correct? What happens if you do this:
    on (rollOver){
    trace(stageRoster);
    stageRoster.loadMovie("playerMovies/hahnJordan09.swf");
    }

    Andrei1, MovieClip.onRollOver is not the syntax Bloom is using, in AS2 you can attach code directly to symbol instances using the on() and onClipEvent() syntax (not putting the code in the timeline.)
     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2008 5:39 PM   in reply to Bloom
    Did you try the trace command? This will put something in your Output window when you test in Flash, telling you if the reference stageRoster/stage_Roster is correct.
     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2008 5:45 PM   in reply to Bloom
    If it does nothing at all then your code is not attached at the time you are rolling over the button. How many keyframes do you have for the button?
     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2008 5:53 PM   in reply to Bloom
    quote:

    Originally posted by: Bloom
    So if I do what Andrei says, it should be using AS3, correct?




    No, what I suggested was AS2 code. This code is used when onRollOver functions is assigned to your button on the main timeline.

    Since you are using the on(rollover) from withing the instance and if stageRoaster is located on main timeline - you need to change the scope of stageRoaster. It either can be _root or _parent:

    on (rollOver) {_root.stageRoster.loadMovie("playerMovies/hahnJordan09.swf");
    }

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2008 6:26 PM   in reply to Bloom
    I was getting ready for dinner and Roster become Roaster. Hmmm... :-)

    Anyway, where is the stageRoster (or Roaster or Grill) relative to the button?
     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2008 7:30 PM   in reply to Bloom
    Can you try:

    on (rollOver) {
    trace("_root.stageRoster: " + _root.stageRoster);
    trace("_parent.stageRoster: " + _parent.stageRoster);
    }

    What is the output?

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2008 8:18 PM   in reply to Bloom
    abeall wrote the code that you need to attach to the button on the main time line. As said before you cannot have a code inside the symbol. Writing class will not make sense because things are happening on the main time line and the only thing you need to make the button do something.

    As for loading a swf - you can use Loader() class and load the swf into a container of your choosing.

    I really suggest you get familiar with AS3 event model. Believe me - without understanding it you will be lost for quite awhile. Event model is a center piece of AS3 and one of the most powerful features of the language. Once you understand it - a lot of tasks will be easy.

    Another thing you need to know is AS3 display list model.


     
    |
    Mark as:
  • Currently Being Moderated
    Dec 25, 2008 10:53 PM   in reply to Bloom
    Buttons are unique in that they resolve relative paths to their parent timeline. In other words stageRoster.loadeMovie is the same as if you had a MovieClip and you had _parent.stageMovie.loadMovie. You shouldn't need to use a Loader component but if it works then go for it.

    Concerning your 9 buttons, in AS3 yes, you would put the code on the buttons' parent timeline at the frame the buttons show up, referencing each button by unique name.

    In AS3 it's basically the same as AS2 except most of the automatic stuff that loadMovie does for you is removed. loadMovie will load the external assets and you see it immediately when it loads at the target you loaded it to. In AS3 the Loader class (different than the Loader component in AS2) is used to load something, then you take an additional step to add it to a timeline (display list) somewhere.
     
    |
    Mark as:
  • Currently Being Moderated
    Dec 26, 2008 7:10 AM   in reply to Bloom
    In addition to Aaron's reply.

    quote:

    Would I write the code for button_jh in the frame of the layer that button is in, or do I just write it in a code layer within that frame?


    In principle it depends on your preferences. It is advisable, though, for manageability sake to write code in layers that are devoted to script only.

    quote:

    I thought using AS2, I could just create a stage, give it an instance name, and load into that.


    I understand that by "stage" you mean a container for you visual elements. Term "stage" has a special meaning in Flash.

    quote:

    Is Loader() new to CS3?


    Yes, it is. There are several features in this class. This class designed to load files that you will be able to manipulate or communicate with in addition to that you will be able to display them. These files are SWFs or images (PNG, GIF, JPEG).

    quote:

    Display list model?


    Yes, display list is a very important thing to understand. In short it is how visual objects are positioned relative to each other. Highlights are:

    Objects are added via addChild, addChildAt methods. There are many methods that allow you to read objects' positions.

    Depth is changed now. There is no negative depths and all the objects are placed in 0-based order WITHOUT gaps.
     
    |
    Mark as:
  • Currently Being Moderated
    Jan 23, 2012 7:45 PM   in reply to Bloom

    Bloom, 3 years later and I'm using CS4 trying to figure out the same thing. In fact, I'm trying to find clear explanations of how action scripts work, how to attach them (my efforts keep not working and also turning off behaviors I've attached. Did you find an answer and can you point me towards a source? Adobe seems to have left the building.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 24, 2012 5:12 AM   in reply to abeall

    >>Yes, it sucks.

     

    No, it doesn't. It was poor style to ever do that and good developers didn't anyway. Now, you're forced to produce cleaner code, as it's more consolidated, and not scattered over a bunch of objects.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points