Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Steven P123

[Solved - user error] Control the main timeline from a tweened clip?

Recommended Posts

Greetings,

 

I have a number of clips set to autoAlpha:0, each on their own layer. I have set up a TimelineMax with pause, resume, and reverse buttons all on the stage. These work just fine.

 

On each tweened clip, I want to set up buttons to pause the timeline (and popup a larger image). Unfortunately, when I put the button listener on the top level (not in a scene but at the top) of the project, I am greeted with the 1120 "undefined property" error. So, I put the listener on a layer within the child clip, and a trace function that works just fine. Unfortunately, I don't know how to reach the parent's TimelinMax instance. I don't even know if this is a child/parent relationship, truth be told.

 

Unable to upload a mini fla (Error No file was selected for upload)

 

Here is (I think) the relative code:

 

top level:

import com.greensock.*;
import flash.events.MouseEvent;
import com.greensock.easing.*;

//create line
var line:Shape = new Shape();
addChild(line);

//position mc at first point
mc.alpha = 0; // calling lineDraw sets alpha '1' each time
mc.x = mc_dot01_08_21_22.x;
mc.y = mc_dot01_08_21_22.y;

var tl:TimelineMax = new TimelineMax({paused:true,onUpdate:drawLine});
var routeLegVar:Number = 5;
var dotPopVar:Number = 0.5;
var grpFadeVar:Number = 1;
var repeatDlyVar:Number = routeLegVar - (2 * grpFadeVar);
////////////////////////////////////////////////
  tl.insert( TweenLite.to(mc, routeLegVar, {x:mc_dot02_07_10.x, y:mc_dot02_07_10.y, onComplete:functionLineClear}), "label_01");

  
// dots
tl.insert( TweenLite.to(mc_dot01_08_21_22, dotPopVar, {scaleX:2, scaleY:2, ease:Linear.easeNone}), "label_01");
tl.insert( TweenLite.to(mc_dot02_07_10, dotPopVar, {scaleX:2, scaleY:2, ease:Linear.easeNone}), "label_02");

// group fades
tl.insert( TweenMax.to(mc_williamsburg, grpFadeVar, {autoAlpha:1, repeat:1, repeatDelay: repeatDlyVar, yoyo:true}), "label_01");

////////////////////////////////////////////////

function drawLine():void
{
	line.graphics.lineTo(mc.x, mc.y);
	mc.alpha = 1;
}

// buttons
play_btn.addEventListener(MouseEvent.CLICK, playTl);
pause_btn.addEventListener(MouseEvent.CLICK, pauseTl);
resume_btn.addEventListener(MouseEvent.CLICK, resumeTl);
reverse_btn.addEventListener(MouseEvent.CLICK, reverseTl);

// 1120 error if placed here:
// btnPop01mWash.addEventListener(MouseEvent.CLICK, pauseTl);

// functions
function pauseTl(e:MouseEvent):void {
	tl.pause();
}

function resumeTl(e:MouseEvent):void {
	tl.resume();
}

function reverseTl(e:MouseEvent):void {
	tl.reverse();
}

function playTl(e:MouseEvent):void
{
	//kill existing line
	line.graphics.clear();
	
	//start new line at first point
	line.graphics.lineStyle(2, 0xFF0000, 1);  // width, color, opacity
	line.graphics.moveTo(mc_dot01_08_21_22.x, mc_dot01_08_21_22.y);
	
	tl.restart();

}

function functionLineClear(){
	//trace('functionLineClear called');
	line.graphics.clear(); // kills all
	line.graphics.lineStyle(2, 0xFF0000, 1);  // width, color, opacity
	//line.graphics.moveTo(mc_dot02_07_10.x, mc_dot02_07_10.y);
	line.graphics.moveTo(mc.x, mc.y);
}
///////// set initial states

mc_dot01_08_21_22.scaleX = mc_dot01_08_21_22.scaleY = 0;
mc_dot02_07_10.scaleX = mc_dot02_07_10.scaleY = 0;


// groups & singles alpha
TweenLite.set(mc_williamsburg, {autoAlpha:0});


And in the 'mc_williamsburg' clip:

// a button with instance name of btnPop01mWash is in this clip

btnPop01mWash.addEventListener(MouseEvent.CLICK, pauseTl);

// functions
function pauseTl(e:MouseEvent):void {
	//tl.pause(); // Does not pause the timeline defined in the top level
	trace('pauseTl called from williamsburg'); // does in fact trace when the button is clicked
}

All items reside in the one file - it's a stand-alone deal.

 

Thanks for any pointers, and best wishes,

Steven

Link to comment
Share on other sites

Solved. Embarrassing, but when I referenced the button from the top level I didn't 'prepend' the button with the clip's instance.

Link to comment
Share on other sites

Thanks for letting us know you solved it. Saves us time.

Don't worry, we all make these mistakes.

 

In the future though, to upload a file, just make sure it is zipped first. That should work.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×