Jump to content
Search Community

Timeline, SplitTextField and allFrom confusion...

Vicware test
Moderator Tag

Recommended Posts

I think I'm missing something. When I run this snippet of code:

 

// introWordA is a standard TextField

var stf1:SplitTextField = new SplitTextField(introWordA);

 

var rollGO:TimelineMax = new TimelineMax({onComplete:rollDone});

rollGO.append(TweenMax.allFrom(stf1.textFields, 0.5, {alpha:1}));

rollGO.play();

 

I get 1067: Implicit coercion of a value of type Array to an unrelated type com.greensock.core:TweenCore.

 

When I change the ".allFrom" to ".to", it works fine.

 

I spent hours searching docs whether there is a prohibition on using SplitTextField with allFrom appended to a timeline.

What am I doing wrong here? I might not be getting the logic completely.

 

 

In a possibly seperate issue: When I do this:

 

var rollGO:TimelineMax = new TimelineMax({onComplete:rollDone});

rollGO.append(TweenMax.to(stf1.textFields, 1, {blurFilter:{blurX:10, blurY:16}, y:"200", autoAlpha:0, ease:Strong.easeOut}));

rollGO.play();

 

I get a series of errors, (presumably during the tweening update cycle):

 

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at com.greensock.plugins::FilterPlugin/initFilter()

at com.greensock.plugins::BlurFilterPlugin/onInitTween()

at com.greensock::TweenLite/init()

at com.greensock::TweenMax/init()

at com.greensock::TweenMax/renderTime()

at com.greensock::TimelineMax/renderTime()

at com.greensock.core::SimpleTimeline/renderTime()

at com.greensock::TweenLite$/updateAll()

 

but when I replace "stf1.textFields" with "introWordA" (standard textfield), it works fine!

 

Can you tell me what rules I'm missing about using this stuff together - I'm sorry for

not finding it in the docs.

 

Thanks -

Vic

Link to comment
Share on other sites

have no fear. there is a simple explanation.

 

allFrom() and allTo() return an array of tweens or in other words... multiple tweens.

 

 

 

 

when using append() with TimelineMax it is for inserting a single tween.

 

you need to use appendMultiple() http://www.greensock.com/as/docs/tween/ ... dMultiple()

 

rollGO.appendMultiple(TweenMax.allFrom(stf1.textFields, 0.5, {alpha:1}));

 

you should be all set.

Link to comment
Share on other sites

I have good news and bad news.

 

I'm using:

 

var stf1:SplitTextField = new SplitTextField(introWordA); //(introWordA and introWordB are standard TextFields)

 

var rollGO:TimelineMax = new TimelineMax({onComplete:rollDone});

rollGO.appendMultiple([TweenMax.allFrom(stf1.textFields, 1, {blurFilter:{blurX:10, blurY:16}, y:"-200", autoAlpha:0, ease:Strong.easeOut}),

TweenMax.to(introWordB, .5, {alpha:1, delay:1, ease:Linear.easeOut})]);

 

//rollGO.play();

 

This works perfectly using appendMultiple - both tweens do what they are supposed to do..

BUT, there are 2 problems:

 

1. When the first tween first starts, I get this error pop up in the output window:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at com.greensock::TimelineLite/insert()

at com.greensock::TimelineLite/insertMultiple()

at com.greensock::TimelineLite/appendMultiple()

at comSlide/aniEngineA()

at comSlide/compHandler()

at flash.events::EventDispatcher/dispatchEventFunction()

at flash.events::EventDispatcher/dispatchEvent()

at com.greensock.loading.core::LoaderCore/_completeHandler()

at com.greensock.loading::LoaderMax/_loadNext()

at flash.events::EventDispatcher/dispatchEventFunction()

at flash.events::EventDispatcher/dispatchEvent()

at com.greensock.loading.core::LoaderCore/_completeHandler()

at com.greensock.loading::SWFLoader/_completeHandler()

 

2. Do you notice that the play command rollGO.play(); is commented out? That's because the

tween starts without it - every time! Can you explain to me why the timeline runs without the

.play??

 

Thank you very much for your help.

Vic

Link to comment
Share on other sites

2: TimelineLite/Max TweenLite/Max instances all play as soon as they are created.

 

if you don't want your timeline to play immediately you can pause it via the contsructor vars:

 

 

var rollGO:TimelineMax = new TimelineMax({onComplete:rollDone, paused:true});

 

or

 

rollGO.paused = true;

 

 

1: the null object errors are difficult to test by just looking at code. if your tweens both work, then there can't be anything wrong with how the targets of the tweens are named.

 

does your rollDone function actually exist? that's my only guess.

Link to comment
Share on other sites

ok - I went through the trouble of creating a simple test program to see why

I'm getting the error:

 

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at com.greensock::TimelineLite/insert()

at com.greensock::TimelineLite/insertMultiple()

at com.greensock::TimelineLite/appendMultiple()

at comSlide/aniEngineA()

at comSlide/init()

at comSlide()

 

every time I run this - right at the beginning of the tween, this happens.

 

I'm attaching the demo file. With this you should be able to tell me what I'm doing

wrong, or if there's a bug in the library.

 

Thanks -

Vic

Link to comment
Share on other sites

thanks so much for providing that demo file. it really helped.

 

I can see how this wouldn't be immediately obvious, but here is why there were errors:

 

When you use appendMultiple() it expects a single array of tweens.

 

allFrom creates a single array of tweens.

 

when you tried to add ANOTHER tween to the appenMultiple() what you were technically doing was creating an Array that had 2 elements

 

element0: the array of tweens created by allFrom()

element1: the TweenMax.to() tween

 

you have an array that contains an array of tweens and a single tween as opposed to a single array of tweens.

 

So when using appendMultiple you can either:

 

-create your own array of single tweens

 

OR

 

-use an array of tweens generated by allTo() OR allFrom()

 

make sense?

 

to achieve the effect you want without errors do this:

 

rollGO.appendMultiple(TweenMax.allFrom(stf1.textFields, .5, {blurFilter:{blurX:10, blurY:16}, y:"-240", autoAlpha:0, ease:Strong.easeOut}, 0.2));

rollGO.insert(TweenMax.to(introWordB, .5, {alpha:1, delay:1, ease:Strong.easeOut}));

 

the introWordB tween will start 1 second after the textfield tweens start.

Link to comment
Share on other sites

I basically understand, although it is confusing to my tired mind.

Thank goodness you gave me the solution to one problem I've been struggling with for the last 24 hours..

 

How about my other question - about .play(); : When I load this swf into my master loop

that plays through a list of images and other swfs, when this swf is loaded it just starts playing:

 

var tempLoader:SWFLoader = new SWFLoader(addTemp, {name:addTemp, estimatedBytes:37000, autoPlay:false, onComplete:compSWF});

tempLoader.load();

 

Is there any way to stop a swf from playing automatically after you load it?

 

Thanks so much for looking at my script.

Vic

Link to comment
Share on other sites

I should also add to the previous post that the onComplete function goes to:

 

private function compSWF(evt:Event ):void {

bitTmpSWF = evt.target.rawContent as MovieClip;

bitTmpSWF.x = 10; bitTmpSWF.y = 9;

addChild(bitTmpSWF); //bitTmpSWF.play();

}

 

Notice that bitTmpSWF.play(); is commented out - the swf should not play, but it does.

 

Vic

Link to comment
Share on other sites

i tried to answer your question about why the timeline plays automatically a few posts above.

you have to put paused:true in the TimelineMax constructor to prevent it from playing.

 

 

this will not work:

var rollGO:TimelineMax = new TimelineMax({autoPlay:false, onComplete:rollDone});

 

 

 

if you are loading this swf via a SWFLoader, autoPlay:false is a SWFLoader property that prevents flash timeline-based animations from playing.

if the swf you are loading has a 30 frame animation, autoPlay:false will make the loaded swf stop on frame 1.

 

 

autoPlay:false when used on a SWFLoader will not prevent your code on frame1 (or in document class) of your loaded swf from executing.

nor will bitTmpSWF.play() cause the TimelineMax timeline to play.

 

so to prevent your TimelineMax from playing do this:

 

var rollGO:TimelineMax = new TimelineMax({paused:true, onComplete:rollDone});

 

now the tricky part is that you need to access that timeline and tell it to play.

 

from the Parent swf that did the loading, you can try something LIKE

 

bitTmpSWF.rollGO.play()

 

the problem you will have is that var rollGO is defined inside your init function and it probably isn't accessible outside of the init function or from another swf.

you may want to declare rollGO as a public var

 

or create an accessible playTimelineMethod that you can call which will in turn call rollGO.play();

 

----

Link to comment
Share on other sites

Great information. Thank you for all the time you put in to give me

some of the intricacies of how to get done what I need to do.

 

It seems about a couple times a year when I venture into new areas of the TM universe

I run into problems that stem more from the conceptual rather than the syntactical.

 

I might have one more question about combining append, insert, etc on the timeline.

I'll try to trudge forward and figure it out.

 

Thanks for your help.

 

Vic

Link to comment
Share on other sites

The paused:true solved my problem of keeping the swf from playing automatically.

 

But, this problem of telling the swf you want to play is a big problem.

 

rollGO is in the swf. The swf is loaded from my document class with swfLoader.

When onComplete is fired after the swf is loaded, it goes there and makes the

swf into the mc, and then displays it. That all works fine:

 

private function compSWF(evt:Event):void {

bitTmpSWF = evt.target.rawContent as MovieClip;

bitTmpSWF.x = 10; bitTmpSWF.y = 9; trace("Hello");

addChild(bitTmpSWF); //bitTmpSWF.rollGO.play(); (your suggestion)

}

 

Except, like you said, the function has no idea what rollGO is - rollGO is in the swf.

 

I've spent over the last 3 years so many late hours figuring out how to get variables shared

and/or passed between classes. But this is different, because this in in a loaded swf, not

another class. So just making rollGO public won't work as far as I know.

 

I thought of some convoluted code that would signal the html via ExternalInterface/javascript to then communicate

to the swf through vars or whatever to tell it to play, but I have no idea if that would work.

 

I was just wondering if you have any ideas on this?

 

Thanks, again -

Vic

Link to comment
Share on other sites

glad to see that you have worked through a lot of the issues.

 

I am the last person you want OOP advice from, but I ran a very simple test and was able to have code in a parent swf's document class, load an external (child) swf and trigger a method in the document class of the loaded child swf.

 

ParentMain.as

 

package {

import flash.display.MovieClip;
import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;



public class ParentMain extends MovieClip {
	var externalSwf:SWFLoader;

	public function ParentMain() {
		externalSwf = new SWFLoader("child.swf",{onComplete:done,container:this});

		externalSwf.load();

	}



	function done(e:LoaderEvent):void {
		trace("done loading");

// this line calls the sqyHello method in ChildMain as soon as ChildMain loads.
		externalSwf.rawContent.sayHello();
//or

externalSwf.rawContent.rollGO.play();
	}



}

}

 

 

ChildMain.as

 

package {

import flash.display.MovieClip;
import com.greensock.*;

public class ChildMain extends MovieClip {
var rollGO:TimelineMax;

	public function ChildMain() {
		trace("main init");
		rollGO = new TimelineMax({paused:true})
		rollGO.append(TweenMax.to(mc, 1, {x:400}));
	}


	public function sayHello():void {
		trace("hello from your friend the external swf");
	}

}

}

 

in short, ParentMain was able to call sayHello() in the loaded swf.

also rollG0.play() can be called directly from ParentMain

 

 

[edit] updated to contain code to control a TimelineMax

Link to comment
Share on other sites

Well, Carl - I couldn't get it to work in my code, so I made

a simple proof (I attached it for any other needy users).

 

Of course, it worked perfectly.

 

In my code I did everything as you have it. No matter what I do, the line

tempLoader.rawContent.rollGO.play(); keeps giving me the same error:

#1009 Cannot access a property or method of a null object reference.

 

I can't understand why I'm getting this. The only thing that is a little different

is that I make the container for the parent SWFLoader a movieclip (so I can

adjust its position) like so:

 

tempLoader = new SWFLoader(addTemp, {name:addTemp, estimatedBytes:40000, onComplete:compSWF, container:bitTmpSWF});

 

I'm not sure if this effects the tempLoader.rawContent.rollGO.play() function.

 

I've tried lots of things like bitTmpSWF.play(); , etc.

 

So other than that I don't know what to do. The code for this is much to much to

have you bothered looking at it. Don't know if I can make a pared down version.

 

If you have any other ideas, please let me know.

 

Thanks -

Vic

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.
×
×
  • Create New...