Groups | Blog | Home
all groups > flash (macromedia) > february 2007 >

flash (macromedia) : Newbie: Runtime programming


akinebs
2/22/2007 11:56:17 PM
I'm new at this. I have made simple applications by adding mc symbols to layers
and then programming actions using event handlers in the actions frame. This
is easy because the instance's name will show-up when the instance is selected.
I just go to it and start a script.

But now I need to use instances that have been created and named at run time
using something like this:

this.createEmptyMovieClip("holderClip", this.getNextHighestDepth());
for (var i:Number = 1; i <= 100; i++)
{
holderClip.attachMovie("Ball_mc", "Ball_mc" + i,
holderClip.getNextHighestDepth(),
{_x:random(550),
_y:random(400)});
}

I want to program the onClipEvent(enterFrame) for these instances. But they
are not on the layer to select yet.. I only know their path and name. Where and
how do I enter the code?
Rothrock
2/23/2007 12:00:00 AM
Here is a great trick. Read the help file for the
MovieClip.createEmptyMovieClip class. Notice how a bit down it says "Returns"?
This means that the method returns a reference to the newly created clip. So
you can assign that to a variable and use it to reference the clip.

Then when you go and read the attachMovie clip?you guessed it. So you can do
something like this:

var curClip=holderClip.attachMovie(blahblahblah);
curClip.onEnterFrame=function(){
this.somethine
}
akinebs
2/23/2007 6:57:23 PM
That seems to work quite well with the onEnterFrame event.

Dragging a mc still is presenting a problem. I have tried:
curclip.onpress =function(){startDrag(curclip,true); }
I get the little hand but the ball doesn't drag?
Have tried many other permutations like:
curclip.onpress =function(){this.startDrag(true); }



Rothrock
2/24/2007 12:00:00 AM
Well your first problem is that you need to capitalize things correctly. onPress and onpress are not the same thing.

curClip.onPress=function(){this.startDrag(true);}

AddThis Social Bookmark Button