Hello,
I'm a Macromedia Director person, and today I began my quest among the
Flash/ActionScript realm.
I don't know if you all know Director, but in short terms when I want to add
a script to an object of my stage, I create a script separately and add it to
the desired objects.
Now for my question: I want to make an object at my stage move based on a
formula. The object is in fact a symbol (which contains an EPS vector image).
In Director it would be very simple to make the object react upon an EnterFrame
event just by creating a simple script with the definition of this event.
Nevertheless I'm having a hard time figuring out how to create the same thing
on Flash.
I already tried to define the onEnterFrame event like this:
this.onEnterFrame = function() {
trace ("entered on frame");
}
but I guess this isn't the way to define events on ActionScript, because I
don't get anything on the Output window.
Can you help me out in order to attach this simple behaviour to an object at
the stage?
Best regards,
Norberto
>Vee< - 30 Dec 2005 02:42 GMT
there is many ways t do this but im gonna use the one i thinkk would most
easily apply.
First give your object (either a movie clip, button or text box) an instance
name to address it by.
Use the property inspector that shows up at the bottom of your screen once you
select the object on the stage. there is a blank field on the top left - that
is where you want to put your instance name (you may keep reusing objects you
have created in your library and just keep switching instance names to address
them). each object must be turned into a symbol which ends up in your library
in which you use in your main movie.
ex: myMC
then on the frame it first appears place your code
myMC.onEnterFrame = function() {
trace ("entered on frame");
}
Try
Norbertofh - 30 Dec 2005 02:54 GMT
Well, I tried that but it doesn't seem to work.
I tried it two different ways:
1) I selected the object (all the frames were selected, I suppose) and placed
the script on the Action panel. This doesn't work at all, as I get the
following error message when I try to enter the Script Assist:
**Error** Scene=Scene 1, layer=CD motion, frame=1:Line 1: Statement must
appear within on/onClipEvent handler
myMC.onEnterFrame = function() {
2) I selected only the first frame of the layer where the object is and
entered the frame. Here there isn't any error, but the output message never
shows.
kglad - 30 Dec 2005 03:01 GMT
myMC.onEnterFrame = function() {
// whatever
}
should be attached to a frame in a timeline that contains myMC. if you want
to attach an enterframe handler directly to a movieclip use:
onClipEvent(enterFrame){
//whatever
}
Norbertofh - 30 Dec 2005 14:11 GMT
>Vee<, I did put the closing bracket at the end, the code I placed on my last
post is what the error message displays.
I tried with either a Symbol or a MovieClip (I converted the original graphic
to these two formats), but unfortunately it still doesn't put any message to
the output window.
This is the code I tried to use:
on(enterFrame) = function() {
trace ("entered on frame");
}
or
onClipEvent(enterFrame) = function() {
trace ("entered on frame");
}
I used these script by selecting the object on the stage and by entering the
code on the Action panel. I also tried it another way, that is by selecting the
first frame of the object and entering the code also on the Action panel.
Nevertheless none of this had any effect.
I'm very sorry for making this hard for you to explain me what to do. I guess
this is mostly due to the fact that I'm still not familiar with ActionScript
and that I come from Director, which seems at a first glance much more friendly
when dealing with scripts and attaching them to objects.
If it is not asking too much, could you provide me an example as a flash
project, just with a symbol outputing messages (with the trace function) as it
goes through frames?
Best regards,
Norberto
>Vee< - 30 Dec 2005 03:01 GMT
did you make it into a symbol first?? meaning does your object appear i the library
kglad - 30 Dec 2005 14:14 GMT
onClipEvent (enterFrame) {
trace("entered on frame");
}
kglad - 30 Dec 2005 14:15 GMT
copy and paste the code. you don't seem to be able to do it otherwise.
Norbertofh - 30 Dec 2005 16:58 GMT
I'm sorry, I was convinced that this forum allowed attachments... now I
realided that the button refers to "attach code" :), my mistake.
Would you mind taking a look at
http://www.norbertohenriques.com/enterframetest.fla in order to see what I did
with your last suggestion? Its a test project that I just created, but I still
didn't manage to get it to work.
Best regards,
Norberto
Norbertofh - 30 Dec 2005 18:22 GMT
Argh, now I understand why it wasn't working! It appears that I have to "test
movie" in order to see what the ActionScript is doing. Until now I was testing
my project just my playing the project.
Is this the way it really works? I mean, can't I test an ActionScript without
having to "Test Movie"? In Director I find it very nice to test my movies just
my pressing Play and seeing all the animation on the Stage panel.
NSurveyor - 31 Dec 2005 00:59 GMT
You can open up the swf itself but then you don't get the benefit of the Debug
panel or the Output Panel. Traces are shown in the output panel, so if you
aren't in the Test Environment, there's no Output Panel, so no traces.
kglad - 31 Dec 2005 00:45 GMT
you're better served to test in the test environment (control/test movie or
ctrl+enter). you can check the actionscript syntax that's in the actionscript
panel by clicking the "check syntax" icon at the top of the actionscript panel.
Norbertofh - 31 Dec 2005 00:55 GMT
Thank you very much for the help. Now it is sort of working as it was supposed
to.
I say "sort of" because I'm having a hard time in Flash as a Director user...
things in Flash seem to be much more complicated to do and to use than in
Director.
In the end I just found out that the enterFrame doesn't even work as I thought
it would work, because it is called even if the animation is stopped (through
the stop() function).
kglad - 31 Dec 2005 01:52 GMT
you're welcome. and i don't know if flash is more complicated than director
but i am sure that i would have a tough time with director because i'm so
familiar with flash.
i think it's tough on people to go from one environment where they have some
degree of expertise to another environment where they have little. our
expectations are great and our tolerance for solving problems in the new
environment is low. it's pretty hard to be patient solving a problem in the
new environment when solving in the familiar environment seems so easy.
Norbertofh - 31 Dec 2005 02:37 GMT
I couldn't agree more with you.
I'm sure it is a matter of being used to the tool. I've been working with
Director since its 5th or 6th version and trying to use the same knowlegde on
the Flash environment is really painful. For instance, I was expecting that the
"enterFrame" event occured when the playhead enters a frame, but now I realise
this isn't the way it works. In Director it is exactly how it works: when the
playhead moves to the next frame, the enterFrame event is triggered, but for
instance if the frames per second is zero (equivalent to a stop'ed() flash
movie) the event is never triggered.
Another issue that I'm having trouble with is the tweening of rotation. In
director there isn't no "auto" or "CW" setting... I just have to create a
keyframe and enter the appropriate custom angle (positive or negative value).
In Flash this task seems, up to now, a hard task to perform.
kglad - 31 Dec 2005 05:47 GMT
yes, that enterFrame handler is counter-intuitive in some ways. but because
the playhead can be moving in any number of timelines and stopped in any number
of other timelines at the same time, it seems pretty arbitrary to tie that
handler to playhead activity in any one timeline or the majority of timelines
or have the handler execute only if all timelines play or only if at least one
timeline plays etc. no matter what you pick, it's probably counter-intuitive
to someone.