Jump to content
Search Community

Dynamic String Value

TripleToe test
Moderator Tag

Recommended Posts

I am trying to tween the data value of a spark Path graphicelement. The data property is a string value. Since it is a dynamic value that changes as the tween progresses, I wanted to do something like this:

 

TweenMax.to(mypath, 1, {dynamicProps:{data:getPathData},  onComplete:onPathAnimationComplete});
....
private function data:getPathData():String
{
   var percent:Number = (TweenMax.getTweensOf(_relationshipPath)[0] as TweenMax).currentProgress;
   return "M 100 " + currentX*percent + " C 10 10" ;  
}

 

The only issue is the the dynamicPropsPlugin only returns a Number value so I'm getting a value of "NaN" when data is set. Clearly this will not work. What is the best way to achieve the setting of a string value that changes dynamically? And is my setting of the percent value a good way to get the progression of the Tween or is there a more efficient way?

 

Thanks

Bill

Link to comment
Share on other sites

I'm not familiar with the "spark Path graphicelement", but if you're simply trying to update a String dynamically, you can use an onUpdate like:

 

var tween:TweenMax = new TweenMax(mypath, 1, {onUpdate:updatePathData,  onComplete:onPathAnimationComplete});
function updatePathData():void {
   mypath.data = "M 100 " + (currentX * tween.currentProgress) + " C 10 10";
}

 

If you need to add easing to that value, you can use a dummy object like:

 

var progress:Object = {value:0};
TweenMax.to(progress, 1, {value:1, ease:Quad.easeInOut, onUpdate:updatePathData});
function updatePathData():void {
   mypath.data = "M 100 " + (currentX * progress.value) + " C 10 10";
}

 

Does that help?

Link to comment
Share on other sites

Yes, this is what I ended up doing and it works for me. I was just thinking it would be cool to use the plugin form, which seems a little cleaner. I guess I could copy the DynamicPropsPlugin and change it to work with a function that returns a string instead of a number, right?

 

Also, is this a good way to get the percentage complete for the tween? Or is there a better way?

 

var percent:Number = (TweenMax.getTweensOf(_relationshipPath)[0] as TweenMax).currentProgress;

 

Thanks! :)

Link to comment
Share on other sites

is this a good way to get the percentage complete for the tween? Or is there a better way?

 

var percent:Number = (TweenMax.getTweensOf(_relationshipPath)[0] as TweenMax).currentProgress;

 

No, I don't like that at all actually. Not only is it cumbersome and very slow, it has the potential for problems if/when there are other tweens of that object (especially if they're TweenLite tweens). You're assuming that the first object in the Array is a TweenMax and it's the one you wanted. Why not just keep track of that instance and reference it when you need to? Like:

 

var tween:TweenMax = new TweenMax(...);
var percent:Number = tween.currentProgress;

 

Not only is this guaranteed to be accurate, it's probably 1000% faster.

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