Hi, I am creating a Twitter to Flash newsticker using a TextBox class. I animate the movement using methods of the TextBox class and TweenLite.
The application runs fine, but after about 15 minutes, the tweenings become very sluggish.
Anyone that has experience with the drawing API, as I think it is related to clearing / deleting the objects…
I would like to see a solution as I can then extend and release this app for anyone that is interested.
////////////////////////////////////////////////////////////////
/// TwitterFApp
/// Developed Jan 2010
package com {
import flash.display.*
import flash.events.*;
import flash.filters.DropShadowFilter;
import flash.text.*;
import flash.utils.*; // for tooltip & setinterval
import flash.net.*;
import gs.TweenLite;
import com.beMobile.TextBox;
import com.swfjunkie.tweetr.Tweetr;
import com.swfjunkie.tweetr.data.objects.StatusData;
import com.swfjunkie.tweetr.events.TweetEvent;
import com.swfjunkie.tweetr.utils.TweetUtil;
import com.swfjunkie.tweetr.oauth.*;
import com.hurlant.crypto.Crypto;
import fl.transitions.*;
import fl.transitions.easing.*;
////////////////////////////////////////////////////////////////
/// TwitterFApp constructor
////////////////////////////////////////////////////////////////
public class TweetrApp extends Sprite {
//generic
public var debug:Boolean = false;
public var i:int= 1;
public var j:int;
public var infoText:Array = new Array ();
public var ttrend: TextBox = new TextBox();
// constants
private static const MINUTE_IN_MILLISECONDS:int = 60 * 1000;
private static const TWEENTIME:int = 2;
public static const TREND_TRESHOLD:int = 5
public static const USER = "";
public static const PASSW = "";
////////////////////////////////////////////////////////////////
/// TwitterFApp main function
////////////////////////////////////////////////////////////////
public function TweetrApp(){
// format
var tf2:TextFormat = new TextFormat();
tf2.bold = false;
tf2.size = 14;
tf2.color = 0x000000; //text color
tf2.font="Myriad Pro";
ttrend.titleFormat = tf2;
ttrend.cornerRadius = 1;
ttrend.autoSize = true;
ttrend.Width = 498;
ttrend.Height = 60;
ttrend.delay = 0.1;
ttrend.bgAlpha = 0.85;
ttrend.align = "center";
ttrend.border = 0xDEDEDE;
ttrend.colors = [0xFFFFFF, 0x50CDDA] // define background color
init();
}
public function init():void {
common()
var tim : Timer = new Timer (6000);
tim.addEventListener(TimerEvent.TIMER, onTick);
tim.start();
var xmlTim: Timer = new Timer (60000);
xmlTim.addEventListener (TimerEvent.TIMER, TweetHandler);
xmlTim.start();
trace ("timer start ");
}
public function TweetHandler(event:TimerEvent):void {
common()
}
public function common():void {
var myTweet:Tweetr = new Tweetr();
myTweet.serviceHost = "http://www.mycomany.com/swf/twitter/proxy";
myTweet.addEventListener(TweetEvent.COMPLETE, myhandleTweetsLoaded);
myTweet.addEventListener(TweetEvent.FAILED, myhandleTweetsFail);
//to set username and password do
// if you are using your own php proxy instance
// you will be able to mask the username and password
myTweet.username = "Tweet_usernam";
myTweet.password = "password";
myTweet.getUserTimeLine("Tweet_usernam", "password");
//myTweet.removeEventListener(TweetEvent, myhandleTweetsLoaded());
}
public function myhandleTweetsLoaded(event:TweetEvent):void{
var displayText:String = "";
for(var i:int = 0; i < event.responseArray.length; i++){
//trace ("event data ", event.responseArray*);
var statusData = event.responseArray*;
//displayText += statusData.user.screenName + "
";
infoText* = statusData.text ;
//output.text = displayText;
} // end for
//trace ("getweetgetListSubscribers", myTweet.getListSubscribers);
} // end functon
public function myhandleTweetsFail(event:TweetEvent):void{
trace ("event ", event.toString);
output.text = "Failed reading Twitter.com !";
}
private function onTick(event:TimerEvent):void {
// will call// the different functions on a regular timebase
if (i>5) {
i=1 ; // reset
}
var infotext:String = infoText* ;
displayBox (infotext);
moveBox ();
i++;
}
private function displayBox (info):void {
ttrend.show( this, info);
ttrend.positionit (this, 5,2);
}
private function moveBox ():void {
ttrend.positionit (this, 5,2);
TweenLite.to(ttrend, 1.5, {alpha:1, y:70, delay:TWEENTIME*2, onComplete: onFinishTween})
}
private function onFinishTween() {
//secondary tween
ttrend.positionit (this, 5,70);
TweenLite.to(ttrend, 1.5, {alpha:0.1, y:"80", delay:TWEENTIME/8, onComplete:deleteBox});
deleteBox();
}
private function deleteBox ():void {
if (debug == true) {
trace (" into function deleteBox ");
}
if (this.parent != null)
{
//removes all objects from the stage
this.parent.removeChild(ttrend);
}
}
}// end class
} // end package