PDA

View Full Version : Hard one to explain- regarding movie clips


Naiive
08-17-2006, 04:57 PM
Alright so i'm making an interactive cd that I want to have menus and whatnot. As is I have a menu(cointaining buttons) within a tween within the main window. I want it to control a movie clip within a movie clip that's within a tween within the main window... I hope this makes sence... I want the movie clip to go to frame 1.
I was trying things like: (the name of the clip i want to be edited is called MOVIECLIPTAB and has 7 coppies nameds btn1 through 7)

for(i= 1; i<=7; i++)
{
_layer0.PhotoButtons.MOVIECLIPTAB["Btn"+i].gotoAndStop(1);
}
//for whatever reason this isn't working? I would really appreciate some help!

galak
08-17-2006, 05:12 PM
Alright so i'm making an interactive cd that I want to have menus and whatnot. As is I have a menu(cointaining buttons) within a tween within the main window. I want it to control a movie clip within a movie clip that's within a tween within the main window... I hope this makes sence... I want the movie clip to go to frame 1.
I was trying things like: (the name of the clip i want to be edited is called MOVIECLIPTAB and has 7 coppies nameds btn1 through 7)

for(i= 1; i<=7; i++)
{
_layer0.PhotoButtons.MOVIECLIPTAB["Btn"+i].gotoAndStop(1);
}
//for whatever reason this isn't working? I would really appreciate some help!
Sme people might screem to what I am about to suggest but I have noticed that the this["whatever" + i] method was quite unreliable try using


eval("_layer0.PhotoButtons.MOVIECLIPTAB.Btn"+i).gotoAndStop(1)

instead... If anyone can tell me why all purist dislike the 'eval' method?

and by the way, when you say '_layer0' don't you mean '_level0' ?

Kraken
08-17-2006, 05:32 PM
well, way back when flash 5 came out with dot syntax, there was a rumor that using eval instead of dot notation was slower. There were some test files that proved it. But, in real-world situations, Robert Penner proved that eval and [] produced the same bytecode when compiled, so there really was no difference. Today, you can use either one with impunity.

However, the problems you've been having were probably due to scope. Using the "this" keyword when referring to MCs is sometimes mis-interpreted by []. Case in point:
http://www.nunomira.com/tutorials/dynamic_references.php#vs

So, use either, but know why and how you're using it.


As to the initial question. Do you mean you have Movieclips that you have tweened by hand on the main timeline and you want them to gotoAndPlay while being tweened? OR are you using flash's Tween class to move them with actionscript?

galak
08-17-2006, 06:02 PM
Hey Kraken, you seem to be quite knowlegable regarding AS's clockwork, could you (god this is going to sound weird and newbie ! ) write or give me a link to an indepth advanced "lesson" on paths ie. this, _parent, _root, _levelx etc.

I don't mean to explain that when you have b_mc inside a_mc you refer to a as _parent.a from b, but really an advanced clarification on paths especially when it gets to pathing from a function nested in other function etc... :o

It is true I sometime have to take twisted paths to get flash to understand what I mean

Kraken
08-17-2006, 06:16 PM
Definitely! Here are a few links I found and some I learned from:
http://timotheegroleau.com/Flash/articles/scope_chain.htm
http://www.bit-101.com/blog/?p=525

and I couldn't find a link, he used to have a sample chapter that explained this, but Branden Hall's book "OOP with Actionscript" also helped me quite a bit:
http://www.amazon.com/gp/product/0735711836/102-0521121-5302557?v=glance&n=283155

zfoley
08-17-2006, 06:53 PM
Here's a great debug tip for noobs learning scope. In the clip you are having trouble finding, you can put:
trace(this);
in its timeline. Then when the instance appears, it will trace itself. You'll see something like:
_level1.someClip

It can be helpful to include a bit of text in your trace to help you find it too like so:
trace("I am the lost clip: "+this);

You can change the string portion and use it in more than one clip so taht you can identify int he output window which clip is calling the trace.

Then after a while you'll get the hang of paths and not need this little crutch any more.

Naiive
08-17-2006, 08:17 PM
MAIN WINDOW
MENU MOVIE CLIP TWEEN (that i just use to slide it onstage)[BUTTWEEN]
BUTTONS IN MENU Movie clip(acting as a button) [Btn1 through 7]

I need to get the movie clip acting as the first button to go to frame 2(so it looks depressed) when either something on the menu is clicked(or if it's easier when that page in teh tween is loaded)
I hope i'm making sence!
thanks!

Kraken
08-17-2006, 08:31 PM
I think you're going to have to post your FLA. I don't understand what you need without seeing what you're doing.

Naiive
08-17-2006, 08:57 PM
Sorry that was supposed to be a tree of everything, but it lost all it's formating... There's no way i can post the flash document cause it's almost 45 mb because there's video and pictures and whatnot that it's storing for high quality playback. Thanks anyway!

Kraken
08-17-2006, 09:08 PM
Can you make a tiny version with only the problematic parts? You could strip out all the assets and just use simple flash shapes to show what you're doing.

Naiive
08-18-2006, 02:08 AM
I stripped it down, took out from the library the stuff that was taking up alot of space. and got it working with just the small amount of frames and saved it. But it is sitll the same file size as it was before. Is there a cache or something I have to clear to drop it's size again? thanks!

zfoley
08-18-2006, 02:11 AM
yeah in the file menu choose "save and compress". That the very reason that command is there :-)

Naiive
08-18-2006, 02:17 AM
I must be a total dumbass cause I can't find that... i have Flash MX version 6... i duno if that's newish or not- is it not on my model?

zfoley
08-18-2006, 02:21 AM
Ahhh - no thats more recent. Just do a save as with a different file name. Like myfile_v2.fla

Naiive
08-18-2006, 02:25 AM
Alright so.... this basically is supposed to work as a photo veiwer. I got the code working on the full version to load the first picture automaticall(it does this via another movie clip overtop the black box) However. I have been unable to get the corresponding movieclip button (number 1) to go highlighted upon it starting up. Any ideas?

zfoley
08-18-2006, 02:34 AM
Hey thenks for the file. I have to run now, but if this is still here in the AM I'll take a look.
I took a quick look at what you sent and I'm still not sure what you're trying to do. Could you restate your original problem with a reference to the file? It might help me find the bug. (Or thers who take alook)

Naiive
08-18-2006, 02:44 AM
Alright so the idea is to have a photo veiwer with categories. The categories are labelled there- when you click on teh categorry it slides out and that 'folder is opened' and it displays the first picture in that folder. It also loads the buttons(those arrow movie clips) based on the number of pictures i have in the album(I did all this manually cause I don't know enough coding to do it with XML or anything). I have it set up so that the buttons remain 'depressed' when you click on them as an identifier to which picture is open. However if you had selected number 4 lets say, when you switch categories it will load the first image but the 4 is still selected. I need it to select the first one in whatever category is opened. This can happen in any way possible.
Thanks! Hope this clarifies!

Kraken
08-18-2006, 02:50 PM
First thing I see is you cannot tell a graphic symbol to gotoAndStop(). It must be a movieclip with a name in order to do that.

Secondly, you've just run into the biggest problem with placing code directly on symbols rather than on the main timeline: fragmentation. You've got so much code scattered everywhere that there's no telling what any of it is doing or how to fix it.

I hate to say it, but you would do well to start over. Instead of placing your code on the buttons, put it in a frame on the timeline and assign it to the buttons. Look up "attachMovie" and "for" loops in the dictionary and use them to attach buttons as needed. You don't need to do anything fancy with XML, just define how many buttons you need in the actions on the frame and attach them to the main timeline. Seriously, there are a million easier ways to do this than what you've got going on. Unless you're under a deadline, I would suggest starting over. Chalk it up to a learning experience and move forward...

and for future reference, the last frame in a button symbol is a place to put a graphic that defines the hitarea of the button. Unless you have something in that frame, flash will just use your text as the hitarea making your buttons hard to click.

Kraken
08-18-2006, 04:22 PM
I took the liberty of modifying your file quite a bit:
http://www.richpaul.com/flash/smallversion/

I placed all the code in the first frame and I'm attaching the photo buttons as needed from the library. I duplicated the category buttons by hand, but the text inside them is assigned dynamically. This could be even smaller if the categories were animated with the Tween class and actionscript. Then, you could attach them like the triangle tab buttons...or create them entirely with code.

Maybe this will help...maybe not...

Naiive
08-18-2006, 05:02 PM
Holy crap your good...
This is my first project in flash, besides fooling around as a kid- and I think I'm way over my head. This is just one portion of the program. I know java which has helped but i've never worked with actionscripting before. It's very interesting but the multitude of different properties is perplexing. As well, what's proving the most difficult is understanding the higherarchy. Like would a stop in a movie clip not stop the whole movie? but one outside wouldn't stop the movie clip either? Independant?

As for what you did, it looks amazing! wow... Unfortunatlyl it's saying unrecognizable file type when I try to open the actual fla document. Any idea why? Thanks again for all this help!

Also is there anyway to open a website without having flash player ask you if your sure and tell the user that it's trying to do that, etc.? Thanks!

Kraken
08-18-2006, 05:46 PM
What version of Flash do you have? I saved it out to MX 2004, but if you have MX it won't work.

What error are you getting when you open a website without flash player?

Naiive
08-18-2006, 06:58 PM
like on one of the menus I have it's using the code. getURL("http"); that one and loading it to a new window. But it always pops up- flash player security. This is trying to access the interenet would you like it to be able to
and oyu hit yes and nothing happens.... so I duno.

I have Macromedia Flash MX Version 6 I beleive

Naiive
08-18-2006, 07:33 PM
to explain- this file is going to run off a cd in the end. so I needed it to link to the web which it doens't like to be able to do. If anyones interested I just got around it by putting a dummy page onto the CD that had a meta link to the actual website(forcing the page to refresh as the actual website)- so by having it do it in two steps I don't get any problems.

Kraken
08-18-2006, 07:40 PM
That has to do with Flash player security and the way IE handles local active X in a web page. If you're producing a CD-ROM I would steer you in the direction of one of the 3rd-party projector enhancers that will help you with things like opening documents, emailing and interacting with the user's OS:
Northcode's SWF Studio (http://www.northcode.com/)
MultidMedia's Zinc (http://www.multidmedia.com/)
Screentime's mProjector (http://www.screentime.com/)

Sorry you can't see my test file...I no longer have a version of MX installed...or MX 2004 for that matter... If you can, I would recommend upgrading. At the very least, your projector will run a bit faster when compiled with a newer version of the flash player.

Naiive
08-21-2006, 08:21 PM
Because I found a roundabout way to access internet sites I don't think I need to pay the money for those bundler programs, though they are very interesting. However where can I learn how to manipulate the flash player(the one that makes a stand-alone exe). Because I want the video to be centred with black all around it instead of the standard windows frame. IS this possible? and if so, how?

Kraken
08-21-2006, 10:35 PM
Look up fscommand in the as Dictionary. Use it like this:

Stage.align = "center";
Stage.allowScale = false;
fscommand("fullscreen",true);


that will put your un-scaled flash projector in the center of a fullscreen window.

Naiive
08-22-2006, 07:07 PM
Thank you so much for your help! I have one more question. I have a movie clip following the mouse(it spins on the spot). That portion of the code works perfectly. However when the mouse leaves the menu I need it to return to it's upright position. That's easy to do, however I need it to be a smooth transition between it's current position and the upright position. For this purpose I was learning timers and trying to figure out how I can get it to do what I want. However, although it seems to run the timer properly it is not re-displaying the movie clip in it's intermediate position before running the loop again. So the result is just a long delay and then it jumps back to the upright position. I hope this is clear!

The code is as follows:

if(_root._xmouse >70 && _root._xmouse<400&&_root._ymouse >320 && _root._ymouse<670)
{
myRadians = Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x);
var myDegrees = Math.round((myRadians*180/Math.PI));

this._rotation = myDegrees+143.5;
timerStarted = false();
}
else
{
this._rotation = myDegrees;
while(this._rotation<10)
{

if(timerStarted==false)
{
timerStarted =true;
numTimeStart = getTimer();
}
else
{
numTimeElapsed = getTimer()-numTimeStart;
if(numTimeElapsed>=100) //tenth of a second between each redraw
{
this._rotation+=10;
timerStarted = false;
gotoAndPlay(this);
}
}
}

}

zfoley
08-22-2006, 07:17 PM
the problem is the while loop. While continues to execute until the condition is false. So it rotates your clip until it is in the stop position. What you want to do is use enEnterFrame or an interfval or something to reduce your rotation. for example:

function onEnterFrame(){
someClip._rotation *=.99; // this line reduces your rotation by 1% each frame
}

Naiive
08-22-2006, 07:26 PM
Thanks! Wow I'm a dunce sometimes! I guess i'm still not used to the fact that clips are infinite loops in themselves.... Thanks!

Naiive
08-28-2006, 02:30 PM
You'll be happy to know i'm going to upgrade in a moment to Adobe Flash Pro 8- so i'll be able to look through what you did for me earlier. However I do have one last question- I posted the code earlier where I was trying to complete a pause. I was able to do that succesfully once directed to the while loop. However for the completed project an object is folowing the mouse while the mouse is over the menu. When it leaves the menu it is returning (smoothly)to it's 'resting' position. I think I have this more or less working. However I need to figure out how to get it to move from that position to the moused over menu smoothly. I think i'm having trouble because the negative x-axis in flash seems to jump from positive to negative 180. I'm having alot of trouble and could sure use some help! I've posted a cutout of my video showing everything i'm having trouble with. Thanks!

Kraken
08-28-2006, 07:01 PM
Ok, when you upgrade to flash 8, take a look at the FLA I'm attaching. In this I have done quite a bit of modification to your code, but I believe it will benefit you substantially.

Naiive
08-29-2006, 03:44 PM
Thanks for everything!

Naiive
08-31-2006, 01:29 PM
I got help with a photoalbum style page earlier on in the week. I have redone the movie and i have put that into it's own movie clip and then brought that into my movie. However, when I do so the dynamic text no longer functions. If i run just that movie clip it works perfectly, but as soon as I put it into the larger picture- nothing. Any help?

Kraken
08-31-2006, 01:33 PM
are you using _root or _level0 anywhere in that loaded SWF? If so, once you load that into another movie, _root refers to the main timeline of the loader movie, not the loaded movie.

If that's not it...you'll have to post another file or more AS...

Naiive
08-31-2006, 01:57 PM
unfortunately this codes too complicated for me so i'm having a hard time following it and knowing where to make changes- and what to- this is one of the ones that works as a stand-alone clip but not overall.
is there any special linkage or anything tricky i'm supposed to have done? (I understand all the coding I just haven't worked much in flash so anything specific to flash i'm having trouble with)


//first thing I do is set up a pointer
//to the main timeline.
var myroot:MovieClip = this;

//Next, let's make an array that will hold
//all our categories.
var catArray:Array = ["Mining & Aggregate","Product Handling","Postal & Parcel","Automotive","Agriculture","Airline","Food","Other"];
var totalCategories:Number = catArray.length;



//we also need to know which category is active:
var currentCat:Number;

//butArray will hold the total buttons for each
//category of photos.
var butArray:Array = [7,5,2,2,4,2,8,1];

//and which photo is currently active:
var currentPhoto:Number = 0;

//what our fonts are
var myformat:TextFormat = new TextFormat();
myformat.color = 0xff0000;
myformat.bold = true;
myformat.font = "_sans";
label_text.setTextFormat(myformat);



//here is the function that each category
//will fire when clicked:
var goCategory:Function = function() {
//let's tell the previous category to go out.
myroot["cat" + currentCat].gotoAndPlay ("out");
currentCat = this.myNum;
this.gotoAndPlay ("at");
goButtons();
}

var goButtons:Function = function() {
//first, let's clear out all the buttons
//from the previous category:
for (item in b_holder) {
if (typeof(b_holder[item]) == "movieclip") {
b_holder[item].removeMovieClip();
}
}
//and now let's attach some new buttons
var tot:Number = butArray[currentCat];
for (i=0;i<tot;i++) {
var tmp:MovieClip = myroot.b_holder.attachMovie("triangle","but" + i,10 + i);
tmp._xscale = 53;
tmp._yscale = 46;
tmp._x = i * (tmp._width + 15);

tmp.t_txt.text = i+1;

tmp.myNum = i;
tmp.onRelease = photoRelease;
tmp.onRollOver = pOut;
tmp.onRollOut = pOver;
}
b_holder.but0.onRelease();
}
var pOut:Function = function() {
this.gotoAndStop("over");
}
var pOver:Function = function() {
this.gotoAndStop("off");
}
var photoRelease:Function = function() {
var curbutton:MovieClip = myroot.b_holder["but" + currentPhoto]
curbutton.gotoAndStop("off");
curbutton.onRelease = photoRelease;
curbutton.onRollOver = pOut;
curbutton.onRollOut = pOver;
currentPhoto = this.myNum;
delete this.onRelease;
delete this.onRollOver;
delete this.onRollOut;
//here is where you'd load your photo into
//the correct place.


_global.category = currentCat;
_global.photo = currentPhoto;
fader_mc.gotoAndPlay(2);
//

myroot.pic_mc.attachMovie("pic" + category + photo,"mypic",5);




this.gotoAndStop("at");
}

var goOver:Function = function() {
if (currentCat != this.myNum) {
this.gotoAndStop("on");
}
}

var goOut:Function = function() {
if (currentCat != this.myNum) {
this.gotoAndStop("off");
}
}

//Now we can set up the text in the
//category buttons:
for (i=0;i<totalCategories;i++) {

myroot["cat" + i].cat_holder.cat_txt.text = catArray[i];
//I also want to assign a function here:
myroot["cat" + i].onRelease = goCategory;
//and its onRollOut and onRollOver functions:
myroot["cat" + i].onRollOver = goOver;
myroot["cat" + i].onRollOut = goOut;
//Keep track of which category this is:
myroot["cat" + i].myNum = i;
//and set its hitarea so it's clickable
myroot["cat" + i].hitArea = myroot["cat" + i].myhit;
}

//put main loading picture


myroot.pic_mc.attachMovie("LOADER","mypic",5);

stop();

Kraken
08-31-2006, 02:21 PM
is this where the text is not getting set? The code looks ok...I think it's mine, actually...ack... Which text is not displaying? How are you creating the textfield that's not displaying, and where is it in relation to the code above?

Naiive
08-31-2006, 02:34 PM
It is yours, you did it earlier this week and suggested if i have the time to redo my whole thing. So I have and it's working great except for this small problem. The text that's not displaying is(if you recall) the numbers that overlay on the buttons. This isn't a big deal to me but for some reason i'm having trouble with all dynamically loaded text except for the one that runs the categories. I beleive you have it setup so that the text feild is within a button movie clip and your editing that 'triangle' movie clips text feild. The code above is within the movie clip (it's more or less exactly what you showed me earlier in this post) except for with my images and within a larger movie.

Kraken
08-31-2006, 03:03 PM
hmm...and the buttons are getting attached correctly? I can't remember if I included the font on those buttons...that could be a problem.

You might just have to post up another small version of your current FLA...