Jump to content
Search Community

running a function using greensock?

Guest newdevide
Moderator Tag

Recommended Posts

Guest newdevide

Hey, Carl, a question please :)

 

I have a script like this:

var f:TimelineMax = new TimelineMax

f.appendMultiple([

new TweenLite(hOpenBan, 0.5, {_xscale:0.01, _yscale:0.01, ease:Back.easeIn}),

new TweenLite(pilTek, 0.5, {_xscale:0.01, _yscale:0.01, ease:Back.easeIn, delay:0.25}),

TweenMax.allTo([lang[0], lang[1]], 0.5, {_xscale:0.01, _yscale:0.01, ease:Back.easeIn, delay:0.5})

])

f.append(TweenLite.delayedCall(5, _root.mhook.loadMovie("comp/swf/start.swf")))

 

I was hoping the last script, would run after the append multiple, but the prob is it run at the same time as the appendMultiple. How do i make the append one run after the appendMultiple is finish??

Link to comment
Share on other sites

2 things:

 

1: When using appendMultiple you can either

--inset your own array of tweens (as you are doing with each new TweenLite(...))

 

OR

 

--use allTo() or allFrom() to create the array of tweens for you.

 

In your code you are using 2 single tweens + an allTo() in your appendMultiple so your results may not be as intended. Basically your appendMultiple is accepting an array that contains multiple tweens plus another array of tweens.

 

2: You are not using delayedCall properly.

You need to specify the name of the function that will run with no parenthesis () or parameters. If you want to pass in parameters, use the onCompleteParams property as noted in the documentation:

http://www.greensock.com/as/docs/tween/ ... layedCall()

 

so you need to do:

 

f.append(TweenLite.delayedCall(5, _root.mhook.loadMovie, ["comp/swf/start.swf"]))

Link to comment
Share on other sites

Guest newdevide

Sorry for the trouble, but the last code doesn't work

 

f.append(TweenLite.delayedCall(5, _root.mhook.loadMovie, ["comp/swf/start.swf"]))

 

Some how it is still not loading the start.swf. I even tried changing the digit 5 to 1.

Link to comment
Share on other sites

Guest newdevide

The first one work

 

The second doesn't :)

 

It works if it were like this:

f.append(TweenLite.delayedCall(5, loadMovie, [_root.mhook.loadMovie("comp/swf/start.swf")]))

 

but then again, it start at the same time with the prev appenMultiple. So the movie loaded instantly, and no animation can bee seen

Link to comment
Share on other sites

f.append(TweenLite.delayedCall(5, loadMovie, [_root.mhook.loadMovie("comp/swf/start.swf")]))

 

the flash player sees loadMovie("comp/swf/start/swf") and runs that code as soon as it is encountered.

 

I suspect this is a typical as2 scope issue

 

viewtopic.php?f=1&t=4337&p=17227&hilit=delayedcall+scope+as2&sid=f56b6a6b8c4b18bae7265048c786689f#p17227

 

try setting the scope with the this keyword

 

TweenLite.delayedCall(.5, _root.mhook.loadMovie, ["comp/swf/start.swf"], this)

Link to comment
Share on other sites

Guest newdevide

Sorry for the late reply

 

Nope it doesn't work either. I really don't know why. But i guess i'll try using the onComplete method to do this.

Thx for the help Carl. But still, i hope someone will find the solution for this hehehe :)

Link to comment
Share on other sites

Guest newdevide

It didn't work either greensock. I forgot to mention...i got this as an output:

 

Target not found: Target="/mhook" Base="?"

 

How will this help solve the prob?

Link to comment
Share on other sites

ok, 1 more problem is that loadMovie needs 2 parameters:

 

1-the url of the swf you are loading

2-the target movie clip that the loaded swf will get loaded into

 

so the code would have had this in your params array:

 

["comp/swf/start.swf", _root.mhook]

 

 

 

but I tried that and all manner of scope finagling and I got the same weird target / base error as you. very strange.

 

what you can do is simply use delayedCall to call your own function that will load the swf for you like:

 

TweenLite.delayedCall(.5, myCustomLoader, this)

function myCustomLoader(){
loadMovie("comp/swf/start.swf", mhook);
}

Link to comment
Share on other sites

Guest newdevide

Now i'm in trouble i change the code to this:

 

f.appendMultiple([

new TweenLite(ripped2, 1, {_x:1600, delay:2}),

new TweenLite(mripped, 1, {_width:0.01, delay:2}),

new TweenLite(mLogo, 1, {_width:0.01, delay:2, onComplete:loadOpen})

])

function loadOpen(){

_root.mhook.loadMovie("comp/swf/open.swf")

}

 

and it wont load the open.swf file

 

I tried this also

 

f.appendMultiple([

new TweenLite(ripped2, 1, {_x:1600, delay:2}),

new TweenLite(mripped, 1, {_width:0.01, delay:2}),

new TweenLite(mLogo, 1, {_width:0.01, delay:2})

])

f.append(TweenLite.delayedCall(1, loadOpen))

function loadOpen(){

_root.mhook.loadMovie("comp/swf/open.swf")

}

 

And it didn't work either

 

Any ideas? Where is the fault?

Link to comment
Share on other sites

Guest newdevide

Ignore the last question, i just found out how, though still no answer to this.

 

If i put it in an 'if' statement somehow it wont work, like this:

 

if(_root.type==0){

var f:TimelineMas = new TimelineMax

f.appendMultiple([

new TweenLite(ripped2, 1, {_x:1600, delay:2}),

new TweenLite(mripped, 1, {_width:0.01, delay:2}),

new TweenLite(mLogo, 1, {_width:0.01, delay:2, onComplete:loadOpen})

])

function loadOpen(){

_root.mhook.loadMovie("comp/swf/open.swf")

}

}else if(_root.type==1){

f.appendMultiple([

new TweenLite(ripped2, 1, {_x:1600, delay:2}),

new TweenLite(mripped, 1, {_width:0.01, delay:2}),

new TweenLite(mLogo, 1, {_width:0.01, delay:2, onComplete:closing})

])

function closing(){

fscommand("quit")

}

}

 

And it works if i don't put my Timeline in an if statement, any ideas?

Link to comment
Share on other sites

i notice you only declare f if type == 0

 

if(_root.type==0){
var f:TimelineMas = new TimelineMax

 

yet if type==1 you try to append tweens to f.

 

 

else if(_root.type==1){
//this code doesn't know what f is.
f.appendMultiple([
new TweenLite(ripped2, 1, {_x:1600, delay:2}),
new TweenLite(mripped, 1, {_width:0.01, delay:2}),
new TweenLite(mLogo, 1, {_width:0.01, delay:2, onComplete:closing})
])

 

I don't know if that is related to your problem or not.

what errors are you getting?

Link to comment
Share on other sites

Guest newdevide

Well, except for the misstype from TimelineMas (i just misstyped it here, sorry)

 

All the tweens are going smoothly except for the end part where i'm trying to load another swf somehow the tweens just stop there, and the loading part wont work

Link to comment
Share on other sites

Guest newdevide

i just tried that and it didn't work either. It wont trace a thing.

 

Id ont' know why, but somehow since i put it in an if statement, all script concerning 'function' wont work. Was there ever a problem like this in AS3?

Link to comment
Share on other sites

i made a very simple example and it works fine:

 

import com.greensock.*;


var f:TimelineLite = new TimelineMax();

var type:Number = 1;


if(type == 1){
f.append(TweenLite.to(mhook, 1, {_x:200, onComplete:myCustomLoader}))

}else{
	trace("type does not = 1");
	f.append(TweenLite.to(mhook, 1, {_alpha:0}));
	}


function myCustomLoader(){
trace("myCustomeLoader()");
mhook.loadMovie("child.swf");
}

 

cs4 files attached

Link to comment
Share on other sites

Guest newdevide

Okey, i'll try that.

So basically i put the IF inside the timline instead of outside the timline right? I'll get back at you after a while

Link to comment
Share on other sites

Guest newdevide

It works,

 

I noted a few stuff:

 

1. Put the if inside the timeline

2. Never define a function inside a timline

 

Thanx Carl

Link to comment
Share on other sites

just to be clear, there is no "inside" or "outside" of a TimelineLite/Max.

 

each command that is used to create a timeline or add tweens to it is its own singular entity without an opening or closing.

 

 

var tl:TimelineMax = new TimelineMax();

tl.append(...sometween...);

trace("i am between two append commands, not inside them");

tl.append(...someOthertween..._)

trace("i am not outside or the timeline, just after it");

 

 

 

on the other hand your if statement does have an inside and an outside:

 

//this code is outside the if statement

if(something == true){
     //this code is inside the if statement
    //you don't want to define functions here
}

//this code is outside the if statement.

 

hopefully this helps. I'm glad you got it working.

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...