View Full Version : AS3 troubles!!
bjkasten
August 20th, 2008, 02:12 AM
I'm very new to Flash and AS3, but I'm getting by after completing Todd Perkins' training book.
I've come across my first obstacle that I'm not able to solve.
I've created a simple animation.
Here is the basic skeleton:
Main Timeline:nested movieclip:multiple nested movieclips.
I have a button on the main timeline to control one of the movieclips in the 'multiple nested movieclips' branch. The code I have in place is :
stop();
function stopbiomovie(event:MouseEvent):void
{
bio_mov.gotoAndStop(1);
}
function playbiomovie(event:MouseEvent):void
{
bio_mov.gotoAndPlay(1);
}
bio_but.addEventListener(MouseEvent.MOUSE_OVER, stopbiomovie);
bio_but.addEventListener(MouseEvent.MOUSE_OUT, playbiomovie);
where bio_mov is the movieclip I want to control. The first nested movieclip is in a keyframe on frame 1 with just a stop(); code in frame 1. When the movieclip finishes, I have code in place to advance the maintimeline to frame 2 and the movieclip remains, looping on its final frame. Everything runs smoothly ... until I add the above code in frame 2. When I add this code and attempt to play the project, the first nested movieclip just skips through, and keeps doing so. No button control. I get the following error messages:
1120: Access of undefined property bio_mov.
1120: Access of undefined property bio_mov.
1120: Access of undefined property bio_but.
1120: Access of undefined property bio_but.
with the following sources respective:
bio_mov.gotoAndStop(1);
bio_mov.gotoAndPlay(1)
bio_but.addEventListener(MouseEvent.MOUSE_OVER, stopbiomovie);
bio_but.addEventListener(MouseEvent.MOUSE_OUT, playbiomovie);
Okay, I hope this is a thorough enough description of the problem and what I'm trying to accomplish. Any help would be great. Thanks.
hasch2o
August 20th, 2008, 03:59 AM
Did you use a reference name for bio_mov and bio_but or is it just the name of the libraryItem?
You have to name the reference AFAIK (haven't done timeline scripting in a while)
bjkasten
August 20th, 2008, 12:12 PM
Did you use a reference name for bio_mov and bio_but or is it just the name of the libraryItem?
You have to name the reference AFAIK (haven't done timeline scripting in a while)
Reference name synonymous with instance name? If so, yes. Those names refer to the instance of the library item on the stage.
snickelfritz
August 20th, 2008, 01:01 PM
Attached is a basic AS3/TweenMax frame navigation fla, with rollover effects, etc...
bjkasten
August 22nd, 2008, 12:37 AM
Attached is a basic AS3/TweenMax frame navigation fla, with rollover effects, etc...
Could you walk me through the AS in that file? Specifically what Child Index means?
snickelfritz
August 22nd, 2008, 02:07 AM
The "child index" relates to the stacking order of children within a parent.
numChildren is the number of children within the movieclip.
There are 10 buttons.
Indexes, in this case are from 0-9.
ie: btn1 is actually index 0, btn2 is index 1, and so forth.
Therefore, it is necessary to subtract (1) from the total number of buttons(10) in order to correctly assign the top index(9) to the e.target.
"e.target as Movieclip" is simply casting "e.target", so Flash will know that it can inherit properties from the MovieClip class.
btnGroup.setChildIndex(e.target as MovieClip, btnGroup.numChildren-1);
In the actions layer nested within "movieclip "btn".
The following commands enable the handcurser for the button,
and disable mouse events for nested children, to mitigate potential problems.
For example, it prevents the instance names for "base" and "btnTxt" from being captured by the btnName variable, instead of the parent button instance name.
this.mouseEnabled = true;
this.buttonMode = true;
this.mouseChildren = false;
Script is now commented for better clarity.
stop();
//import statements for the TweenMax classes.
import gs.TweenMax;
import gs.easing.*;
//event listeners are attached to the parent movieclip container.
//events propagate to the children, in this case, the buttons.
This allows this set of listeners to serve a virtually unlimited number of buttons.
btnGroup.addEventListener(MouseEvent.MOUSE_OVER, btnOver, false, 0, true);
btnGroup.addEventListener(MouseEvent.MOUSE_OUT, btnOut, false, 0, true);
btnGroup.addEventListener(MouseEvent.CLICK, btnClick, false, 0, true);
//btnTxt is a dynamic text field nested in the "btn" movieclip.
//the following sets the labels that will be visible to the user.
btnGroup.btn1.btnTxt.text = "button1";
btnGroup.btn2.btnTxt.text = "button2";
btnGroup.btn3.btnTxt.text = "button3";
btnGroup.btn4.btnTxt.text = "button4";
btnGroup.btn5.btnTxt.text = "button5";
btnGroup.btn6.btnTxt.text = "button6";
btnGroup.btn7.btnTxt.text = "button7";
btnGroup.btn8.btnTxt.text = "button8";
btnGroup.btn9.btnTxt.text = "button9";
btnGroup.btn10.btnTxt.text = "button10";
//
function btnOver(e:MouseEvent):void {
//sets the index of the e.target to the top of the stack.
//basically, this allows the button that is rolled-over to be on top of the the other buttons.
//is useful if the rollover action causes the button to overlap the other buttons.
btnGroup.setChildIndex(e.target as MovieClip, btnGroup.numChildren-1);
//very basic TweenMax rollover effect
TweenMax.to(e.target.base, .2, {tint:0x0066FF, scaleY:1.2});
TweenMax.to(e.target.btnTxt, .2, {x:40});
}
//this function tweens two children of the btn movieclip simultaneously.
//"base" movieclip is just a colored rectangle.
//"btnTxt" is a dynamic textfield.
function btnOut(e:MouseEvent):void {
TweenMax.to(e.target.base, .8, {removeTint:true, scaleY:1});
TweenMax.to(e.target.btnTxt, .6, {x:10, ease:Bounce.easeOut});
}
//this empty variable is waiting for a string.
var btnName:String = "";
function btnClick(e:MouseEvent):void {
//the btnName variable is assigned a string value.
//in this case it is the button instance name, since the button is the e.target.
btnName = e.target.name;
stageText.stageTxt.text = btnName + " click";
//example of a TweenMax sequence.
TweenMax.sequence(stageText,[{time:.6, scaleX:2, scaleY:2},{time:.8, rotation:360, ease:Back.easeIn},{time:.8, scaleX:1, scaleY:1, rotation:0, ease:Back.easeOut}]);
gotoAndStop(btnName);
}
bjkasten
August 23rd, 2008, 10:31 PM
REALLY new to AS3 so most of this is over my head. If I post two files, one pre-error and one post-error, would you be able to diagnose my problem?
fatboyslim007
August 24th, 2008, 03:02 AM
I'll diagnose your issue. Post your files, and explain what you want it to do.
snickelfritz
August 24th, 2008, 03:55 AM
REALLY new to AS3 so most of this is over my head. If I post two files, one pre-error and one post-error, would you be able to diagnose my problem?
Go ahead and post the fla.
bjkasten
August 25th, 2008, 04:50 AM
I'll diagnose your issue. Post your files, and explain what you want it to do.
okay - the only difference between the two files is some actionscript added to frame 18 on the project "new bg - error"
this is what i want to happen: the animation will play fully. when it ends, the symbols within the red balls (which are nested movie clips) will continue to animate. over each of these symbols is an invisible button. when the mouse hovers over the button, the corresponding symbol movie clip will stop on it's first frame (thus being invisible) and the OVER state of the button will appear (which is an instance of the symbol when it's bright).
that all make sense?
thanks for helping me out.
bjkasten
August 28th, 2008, 01:54 AM
I'll diagnose your issue. Post your files, and explain what you want it to do.
alright - 'tis up whenever you may have some time.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.