Jump to content
Search Community

Help! Using BlitMask with dynamic textFields that are being updated

eco_bach test
Moderator Tag

Recommended Posts

Panic deadline and I am trying to get something to work using BlitMask in conjunction with a dynamic Textfield that I am appending text to. In order to add (append) text I need to disableBitmapMode and dispose of the old Blitmask, add my text, then create a new Blitmask
 
The issue is that the Blitmask is NOT auto wrapping properly.
 
The following will work if you drop in an fla. I've also attached an fla with identical code.
 
/*
We are simply updating a dynamic textfield that is also endlesslly looping left to right


We are also using a BlitMask to optimize performance and provide the autowrap functionality


*/
import flash.events.*;
import flash.utils.Timer;
import com.greensock.*;
import com.greensock.easing.*
import flash.text.TextField;






var _debugTxt:String='Jack and Jill went up the hill to fetch a pail of water. Jack fell down and broke his crown and Jill came tumbling after This is at the end!!';
var _debugPool:Array=_debugTxt.split(" ");
var _blitMask:BlitMask


var tf:TextField;


var pollTimer=new Timer(2000, 0);
pollTimer.addEventListener(TimerEvent.TIMER, timerHandler, false, 0, true);
var count:int=0;






function timerHandler(event:TimerEvent):void {
if (_blitMask != null) {
_blitMask.disableBitmapMode();
_blitMask.dispose();
}
var tagTxt:String=_debugPool[count];
count=int(count + 1);
trace('tagTxt ='+tagTxt);
trace('getMetrics(tf).width ='+getMetrics(tf).width);
if (getMetrics(tf).width < 1920) {
tf.appendText(tagTxt.toUpperCase());
}
if (_blitMask == null) {
_blitMask=new BlitMask(tf, tf.x, tf.y, 1920, 50, true, true, 0x000000, true);
}
//NB only tween once for repeating tween
if (TweenMax.isTweening(tf) == false) {
//this['_blitMask'+j] = new BlitMask(tf, tf.x, tf.y, 1920, _bannerH, true, true, 0x000000, true);
TweenMax.to(tf, 20, {x: 1920, repeat: -1, onUpdate: _blitMask.update, ease: Linear.easeNone}); //onUpdate:this['_blitMask'+j].update,
}
}


function getMetrics(tf:TextField):TextLineMetrics {
var tm:TextLineMetrics=tf.getLineMetrics(0);
//trace('getMetrics and metrics.  ='+tm.width);
return tm;
}




//start everything!


pollTimer.start();

 

Link to comment
Share on other sites

This is a simple BlitMask example WITHOUT updating a dynamic TextField that works as it is supposed to.

How do I update the text AND keep the BlitMask functionality?

 

We are using a BlitMask to optimize performance and provide the autowrap functionality


*/
import flash.events.*;
import flash.utils.Timer;
import com.greensock.*;
import com.greensock.easing.*
import flash.text.TextField;
var _blitMask:BlitMask;


var tf:TextField;


_blitMask=new BlitMask(tf, tf.x, tf.y, 1920, 50, true, true, 0x000000, true);


TweenMax.to(tf, 20, {x: 1920, repeat: -1, onUpdate: _blitMask.update, ease: Linear.easeNone});

 

Link to comment
Share on other sites

In your original code, you were destroying the BlitMask after the first iteration and you never re-enabled it or anything. That's why you're not seeing it work :)

 

There's no reason to keep killing/recreating the BlitMask instance either. You can simply call update() and force a recapture using the second parameter. So your timerHandler() would look like this:

function timerHandler(event:TimerEvent):void {
	var tagTxt:String=_debugPool[count];
	count=int(count + 1);
	if (getMetrics(tf).width < 1920) {
		tf.appendText(tagTxt.toUpperCase());
	}
	if (_blitMask == null) {
		_blitMask=new BlitMask(tf, tf.x, tf.y, 1920, 50, true, true, 0x000000, true);
	} else {
		_blitMask.update(null, true); //force a recapture of the Bitmap since we changed it.
	}
	if (TweenMax.isTweening(tf) == false) {
		TweenMax.to(tf, 20, {x: 1920, repeat: -1, onUpdate: _blitMask.update, ease: Linear.easeNone});
	}
}

Does that help?

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