View Full Version : Target a specific frame in an MC for display
If my mc has a number of frames, each with a different graphic or movieclip.
the first question -is do I want each object in the frame to be a movieclip -think so
The second question would be initially getting the mian MC to stop
(should i just instert stop actions in each frame)
This would be the psuedo code I think:
var myClip:MovieClip = new MyClip ();
addChild (myClip);--which spawns the main mc frame 1
but to access frame 2 with it's respective frame labeled "second"
would I call it like this?
var myClip.second:MovieClip = new MyClip.second ();
addChild (myClip.second);
I am not sure if this is doable-this way
I can use myclip.gotoAndstop(2) or ("second"); in a function -I know that which is 1/2 of it
Mendyman showed me an example of using it in AS2 with an array.
I would like to know how to call up parts of a movieclip as instances.
Medyman
06-16-2008, 11:09 PM
the first question -is do I want each object in the frame to be a movieclip -think so
If you want actions applied to the graphics on each frame, yes. Otherwise, no.
The second question would be initially getting the mian MC to stop
(should i just instert stop actions in each frame)
You only really need stop functions on the first frame. After that you'll be using gotoAndStop() so the stop action is implied.
Mendyman showed me an example of using it in AS2 with an array.
Where did I show you this? I can show you how to do it in AS3 if I know what the original code was.
The example you gave was here (http://www.visualbinary.net/files/tutorials/toolbar/)
I looked at it again and I think I need something else
I have an MC with a timeline, 2 frames
I am creating interfaces with buttons -so each mc frame contains a different set of buttons. The mc would the called "interface.mc".
Fame 1 and Frame 2 are labeled "group1" "group2" there is a stop action in frame 1
I placed "inteface_mc" in the main timeline (is that ok -is there a greater advantage in creating an instance of it.)
The first problem I had is it isn't recognizing my buttons.
I set up and EventListener with a button -button"doIt" inside the mc.
doIt.addEventListener(MouseEvent.CLICK, makeIthappen);
function makeIthappen(e:MouseEvent):void{
trace(Dynamicdrive.com is cool);
}
I get an error that says:
ReferenceError: Error #1065: Variable doIt_btn is not defined.
at inteface_fla::MainTimeline/inteface_fla::frame1()
Here (http://www.asmakta.com/clients/new_gor/colorbuttons1a.html) is a working example -only I used the MAIN timeline to "change" buttons
even though they look identical. This is the "messy" way.
Medyman
06-19-2008, 10:32 PM
Hey Evan…
First, let me say that I’m thoroughly confused by what you’re doing (i.e. your setup). I think I know what you’re trying to do though. So, here (http://www.visualbinary.net/files/tutorials/wise-words/) is a little example I just created to demonstrate what I think you’re looking for. Before I explain it though, let me just confirm some things.
As I understand it, your dilemma is the following:
You have one movieclip each on one of two frames within a larger container movieclip (interface_mc). You’re trying to access the movieclip on frame 2 of interface_mc and notice that Flash says it doesn’t exist. Correct?
The issue here is that the movieclip doesn’t exist – at least not within the scope that you’re assigning to it. Actionscript added to a frame of a movie only has purview over that particular frame. So, if you add actions on frame 1 to control a movieclip that doesn’t exist until frame 3, that won’t work. Why? Because, when Flash assigns actions to all the clips at frame 1, the movieclip at frame 3 didn’t yet exist so no actions were applied. In other terms, think of a workplace. The boss of a company assigns tasks to his employees at 8:00 AM. So,Employee X (ever the slacker), who wasn’t at that meeting doesn’t know what to do when he comes in at noon. That’s the first issue.
The second issue is that the main timeline doesn’t really have jurisdiction over the timeline of constituent movieclips. So, if your interface_mc has two movieclips inside it (button1 on frame 1 and button2 on frame2), you can’t call these clips directly.
You can call button1 via a relative path to button1 (interface_mc.button1). That gets rid of the problem with the main timeline’s jurisdiction. But, how do you access button2? Interface_mc.button2 doesn’t seem to work! Well, think about what I said earlier. Button2 didn’t exist when that ActionScript ran. Button2 was late to work, or more appropriate in this case, in another room.
You might think that it’s possible to write a gotoAndStop() call and then right after it attach a function to something within the container. But, this again isn’t the solution. Flash’s internal parsing order denies this from happening. As it turns out, by the time Button2 leaves the other room to come into the meeting, the boss finishes assigning the tasks.
So, how is it possible to add events or reference movieclips contained on frames other than frame 1 in constituent movieclips? Well…there are 2 ½ solutions:
1) Write your actionscript within the right scope. This means, put your actionscript that you want attached to a certain movieclip in a layer that has direct access to it. In your example, you would write ActionScript written about Button2, on frame 2 of interface_mc.
2) In a similar vein, you can create object-oriented programming techniques. Then, the viewpoint of coding shifts from a global view of the entire application to a local view of how one object interacts within the application. You still have an issue with calling objects that appear on frame 2 of a certain “object”, but that’s fixed by using some secret flash techniques. If you’re a serious Flasher, you’ll know about the undocument AS3 method called addFrameScript(). This method allows you to attach functions from one frame to another. So, I can dynamically attach AS3 code to movieclips that I’m building dynamically.
2 ½) Write ActionScript so that it calculates what’s on the stage dynamically. This is what I’m demonstrating with my example.
The example has a simple application. It cycles through some cultural icons and shows a small “quote” from them or something they’re associated with. All of the icons are separate movie clips contained within a container movieclip (instance name “icons”). The next button is referencing the icons movieclip and increasing the frame by one each time. If you’re at the end of that timeline (frame 6 in that case), it goes back to one. Clicking on the little icon itself, shows an image of the person in question. The name for the image is derived from the instance name of the icon. If you open up the icons movieclip, you’ll see that I’ve named each icon something different. I then dynamically reference that in my showImage() function.
Again, I was confused by your post. But maybe this example will come to some use. The fully commented code is added to the example page. As always, it’s all released under Creative Commons NC.
Let me know if you have any questions
that is very usefull, in the sense that it shows how to display frames, of a movieclip.
This offers more flexibilty than just using the timeline.
What I was trying to mention in my earlier post was, what if I did that AND then the targeted frame in the movie clip had interractivity assigned to it's objects.
Medyman
06-24-2008, 11:10 PM
What I was trying to mention in my earlier post was, what if I did that AND then the targeted frame in the movie clip had interractivity assigned to it's objects.
Right...
You can do that as well. Just like I'm pulling the names.
Using the getChildAt() method.
So, if you were trying to attach a CLICK mouse event to a movieclip on frame 2 of another movieclip (instance name interface), you might do something like this:
instance.gotoAndPlay(2);
instance.getChildAt(0).addEventListener(MouseEvent.CLICK, onClick);
Of course, this doesn't guarantee that you're accessing the right movieclip. If the gotoandPlay doesn't complete on time, it will add the actions to the child at level0 on the first frame.
You could also use addFrameScript():
interface.addFrameScript(2, frame2);
function frame2() {
interface.buttonOnFrame2.addEventListener(MouseEvent.CLICK, onClick);
}
check this out (http://asmakta.com/clients/gogorilla/studio/studiobeta.html)
this is a cleaner version of what I'm working on. I resorted to putting the interface for the markers into a second frame.
at a first glance, can do you have any suggestions.
The code is pretty long for it to be intelligible here.
Medyman
06-28-2008, 09:12 PM
Seems good so far. Without looking at what's under the hood, I can't really make any suggestions.
But everything seems to be running smoothly and functioning properly. Seems like you're on the right track. It's good to see the result of all of these threads :D
Keep it up.
Let me see if I can post it for you meanwhile, I think I figured it out.
The bug here is that after you use the markers and go back to the pencils, it clears the screen when I don't want it to.
in this version, I have an API drawing board that contains the drawing, I borrowed that from the Flash, and Math paintool -I can also use a library mc and set the alpha to "0" but that has dissadvantages. so, apparently there is no way to get around coding it this way.
I think the bug is caused because I work with two frames, frame 1 has the pencils, Frame 2 has the markers. The user starts drwing with pecils, then goes to frame 2 and draws with the markers, then clicks the button to use the pencils again and then:POOF
the whole drawing is erased!
why? because it goes back to frame 1 where the code instructs it to draw an API drawing board! in other words the "program" restarts because frame 1 is the place where the code tells flash to draw an artboard!
I can fix this(I Think) by toggling the tools between frames, 2 and 3 not 1, and 2
I just tested the theory and here it is -bug fixed (http://www.asmakta.com/clients/gorillapub/DEMO_BETA1_BFIX.html)
OR I can implement what you are showing me here. The lesson learned here is Yes, using fames is an easy quick and dirty way to get things done, but I think keeping stuff in Frame 1 is better, and using frame by frame with intercativity is better served for flash docs imported in to the main doc, and either coding animation, or changing tweens into actionscript.
Thankyou for your effort and help, I have learned much sensie master
1172: Definition caurina.transitions could not be found. lines 1,3
1120: Access of undefined property Tweener. lines 72,77
--SCRATCH THAT I impoted the class from the Corina folder the comment pointed the link. OK brain fart
each time mc icons
as in
icons.addEventListener(MouseEvent.CLICK, showImage);
var photo:MovieClip = new MovieClip();
addChild(photo);
function showImage(e:MouseEvent):void {
photo.alpha = 0;
var loader:Loader = new Loader();
loader.load(new URLRequest(icons.getChildAt(0).name + ".jpg"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fadeImage);
photo.addChild(loader);
photo.addEventListener(MouseEvent.CLICK, hideImage);
}
I understand where it works but I am curiose as to how.
It makes to refference to each photo, yet each picture corresponds perfectly with each icon.I see that with icons.getChildAt(0).name+"jpg")); it calls up a picture in order but how does it know which one is first second etc.?
the photos are all named Monroe, Elvis etc.
Medyman
07-02-2008, 09:19 PM
Ok...let me break this down.
There are a few things at play here.
1. The next button on the main timeline.
2. The icons (one each on each frame) in the icons movieclip
3. Each icon has an instance name that is the same as the .jpg image I want to call
The "next" button manipulates what frame the icons movieclip is on. When you click on an icon, it runs the showImage() function.
What the showImage() function is saying is this: load an image with the filename equal to the instance name of the movieclip on _level0 of the icons movieclip. So, it goes to the icons movieclip, looks to see what movieclip is currently showing, and then gets it's instance name. Next, it loads the_instance_name.jpg onto the stage.
So icons.getChildAt(0).name refers to whichever movieclip is on _level0 of icons.
Does that answer your question?
It does, big time. I love seeing examples where more than one thing gets done and(to me) it's not apparent right away. Good stuff.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.