Copy link to clipboard
Copied
when i create a new document in Flash CS3 with choosing "ActionScript 3.0", i cannot edit the action script for any clips/buttons i made and when i pressed F9, it showed "current selection cannot have actions applied to it". however, when i created a flash file with selecting ActionScript 2.0, I have no such issue any more.
Do you know why ?
Copy link to clipboard
Copied
AS3 does not allow code to be applied onto objects as AS2 does. All code in AS3 must be placed on the timeline.
Copy link to clipboard
Copied
And even though AS2 allows you to do such a thing it really isn't a good idea. For me the worst part about putting code on items is that if you have more than one item and then you make a change you have to go find all the places where that code is kept.
When Flash 6 came out you it allowed you to put the code on timelines and that made everything better. I really recommend this article on why.
http://www.quip.net/blog/2006/flash/museum-pieces-on-and-onclipevent
BTW. If you didn't know about this, my guess is that you don't know about the new way of handling mouse events and, well actually, ALL events in AS3.
So here it is. The item that has (dispatches) the event gets a listener added to it for that event and the listener has a function that handles the event. Like so:
myButton.addEventListener(MouseEvent.MOUSE_DOWN,buttonPressed)
function buttonPressed(e:MouseEvent):void{
trace(e.target+" was pressed.");
//whatever you want to do when the button is pressed
}
or like this:
myClip.addEventListener(Event.ENTER_FRAME,someFunction)
function someFunction(e:Event):void{
trace(e.target+" has entered frame.");
// whatever you want to do
}
Of course in both cases you don't need the trace I just wanted you to have something to see that would happen. And to point out the importance of the event argument that the function will (must) receive).
There are lots of posts about the differences between AS2/3 so take a search and then post back with more questions as you have them.
Copy link to clipboard
Copied
In addition to what other guys said, in terms of your question there is just a bit of perspective change.
In AS2, as you know, you could place code on the object's internal timeline. So, basically, compiler created all the associations (properties, methods) to the object and its code automatically.
In essence, one can do the same thing in AS3. The only difference is that the object just needs to be linked to a class that does what "internal" timeline was doing in AS2.
I am not claiming that my explaination is totally accurate. I am just saying that conceptually it is the same thing except the code resides in a separate .as file - not on a timeline.
BTW, I love AS3 approach for many reasons. I find it much more reliable, convenient and comact. As a matter of fact I practically stopped using timeline altogether (with the rare exceptions of complex animations that are combersome to describe in code) when I learned AS3.
Copy link to clipboard
Copied
>>In AS2, as you know, you could place code on the object's internal timeline. So, basically, compiler created all the associations (properties, methods) to the object and its code automatically.
What you wrote there works exactly the same way in AS3, and it's just as successful. It's only the attaching script to the object itself that doesn't work anymore.