Sunday, April 4, 2010

Autoscroll

Hello, I'm trying to autoscroll some text but its not working. Can someone help me? Here is my code:

%26lt;mx:Script%26gt;
%26lt;![CDATA[
import flash.display.MovieClip;
?import flash.media.Sound;
?import flash.events.Event;
?import flash.net.URLRequest;
?import flash.media.SoundChannel;
?import flash.events.TextEvent;?

?public var _sound:Sound = new Sound();
?public var _soundChannel:SoundChannel;
?public var _resumeTime:Number;
?public var _right:Shape;
?public var _left:Shape;
?public var timer:Timer;

?private function initApp():void {

?var request:URLRequest = new URLRequest (''audio/'');
?_sound.load(request);
?_sound.addEventListener(Event.COMPLETE,onLoad);?
_soundChannel= _sound.play();
?_right = new Shape();
?_left = new Shape();
?addChild(_right);
?addChild(_left);
?_left.x = 200;
?_right.x= 250;
?addEventListener(Event.ENTER_FRAME, onEnterFrame);
?}?
?
?private function onEnterFrame (event:Event):void{
?_right.graphics.clear();?
?_left.graphics.clear();
?_right.graphics.lineStyle( 0, 0x000000, 1);
?_left.graphics.lineStyle(0, 0xFFFFFF, 1);
?_right.graphics.drawRect(0,0,20,100*_soundChannel.rightPeak);
?_left.graphics.drawRect(0,0,20,100* _soundChannel.leftPeak);
?}

private function onLoad():void{?
?enabled = true;
}
?
?public function onStop():void{
?_resumeTime = _soundChannel.position;
?_soundChannel.stop();

}

public function onPlay():void{?
_soundChannel = _sound.play(_resumeTime);
?}?
?private function sendInfo():void{
?if(username.text=='''' || email.text=='''' || msg.text==''''){
?mx.controls.Alert.show(''Please verify your form!'')
?} else {
contactService.send()
?}
?}

private function thanks(evt:Event):void{
?if(String(contactService.lastResult)==''ok'') currentState = ''thanks''
?else mx.controls.Alert.show(''Errors sending email!'')
?}
public function linkHandler(event:TextEvent):void {
?
?
?// Open the link in a new browser window.
?navigateToURL(new URLRequest(event.text), '_blank')
?}

?private function init():void {
?timer = new Timer(500);
?timer.addEventListener(TimerEvent.TIMER, onTimer);
?timer.start();
?}

?private function onTimer(evt:TimerEvent):void {

?textArea.text = '' Hello welcome to the site''
?textArea.validateNow();
?textArea.verticalScrollPosition = textArea.maxVerticalScrollPosition;
?}

?
?

]]%26gt;
%26lt;/mx:Script%26gt;

%26lt;mx:Move id=''showeffect2'' yFrom=''300''/%26gt;
%26lt;mx:Move id=''hideeffect2'' yBy=''600''/%26gt;
%26lt;mx:Fade id=''fadeOut'' duration=''1000'' alphaFrom=''1.0'' alphaTo=''0.0''/%26gt;
%26lt;mx:Fade id=''fadeIn'' duration=''1000'' alphaFrom=''0.0'' alphaTo=''1.0''/%26gt;

%26lt;mx:LinkBar color= ''#FFFFFF'' height=''28''?dataProvider= ''{tabNav}'' backgroundColor=''#e489cd''?borderStyle=''solid'' width=''867'' borderColor=''#FFFFFF'' selectionColor=''0xffffff'' separatorColor=''0xcccccc''?rollOverColor =''0xe489cd'' textRollOverColor=''0xcccccc''?textSelectedColor=''0x000000'' x=''100'' y=''28''/%26gt;?

%26lt;mx:ViewStack id=''tabNav'' borderStyle=''solid'' width=''867'' height=''485''?x=''100'' y=''75''%26gt;
%26lt;mx:VBox id=''Home'' backgroundImage=''@Embed(source='assets/StephanieHBoxmain.jpg')'' showEffect=''showffect2'' hideEffect=''hideeffect2'' horizontalAlign=''center'' verticalAlign=''middle'' label=''Home''?width=''100%'' height=''100%'' borderStyle=''solid''?borderColor=''#FFFFFF'' %26gt;

%26lt;mx:TextArea id=''textArea'' width=''424'' height=''296'' paddingTop=''130'' paddingBottom=''100'' backgroundImage=''@Embed(source='assets/textareahome.jpg')'' borderColor=''#FFFFFF''?borderStyle=''solid'' borderThickness=''2'' color=''#FFFFFF''?backgroundColor=''#e489cd'' shadowDirection='''' wordWrap=''true'' horizontalScrollPolicy=''off'' fontSize=''18'' textAlign=''left'' verticalScrollPolicy=''on'' editable=''false'' %26gt;
?
?
%26lt;/mx:TextArea%26gt;

Autoscroll

Try using callLater to set verticalScrollPosition=maxVerticalScrollPosition. I think the scrollpositions don't get updated until the end of the drawing phase.

Also, it looks like you're just setting the text to a small sentence so there may not be anything to scroll

Alex Harui

Flex SDK Developer

Adobe Systems Inc.

Blog: http://blogs.adobe.com/aharui

Autoscroll

I tried this and didnt work

private function init():void {
?timer = new Timer(500);
?timer.addEventListener(TimerEvent.TIMER, onTimer);
?timer.start();
?}

?private function onTimer(evt:TimerEvent):void {

?textArea.text = '' Hello welcome to the sitedffdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdffdfdfdfdfdfdfdfdfdf''

ddfdddddddddddddddddddddddddddf
?textArea.validateNow();
?callLater(autoScrollTextArea, [textArea]);

?}

private function autoScrollTextArea(target:TextArea):void{
target.verticalScrollPosition = target.maxVerticalScrollPosition;
}

%26lt;mx:LinkBar color= ''#FFFFFF'' height=''28''?dataProvider= ''{tabNav}'' backgroundColor=''#e489cd''?borderStyle=''solid'' width=''867'' borderColor=''#FFFFFF'' selectionColor=''0xffffff'' separatorColor=''0xcccccc''?rollOverColor =''0xe489cd'' textRollOverColor=''0xcccccc''?textSelectedColor=''0x000000'' x=''100'' y=''28''/%26gt;?

%26lt;mx:ViewStack id=''tabNav'' borderStyle=''solid'' width=''867'' height=''485''?x=''100'' y=''75''%26gt;
%26lt;mx:VBox id=''Home'' backgroundImage=''@Embed(source='assets/HBoxmain.jpg')'' showEffect=''showEffect'' horizontalAlign=''center'' verticalAlign=''middle'' label=''Home''?width=''100%'' height=''100%'' borderStyle=''solid''?borderColor=''#FFFFFF'' %26gt;

%26lt;mx:TextArea id=''textArea'' width=''424'' height=''296'' paddingTop=''250'' paddingBottom=''100'' backgroundImage=''@Embed(source='assets/textareahome.jpg')'' borderColor=''#FFFFFF''?borderStyle=''solid'' borderThickness=''2'' color=''#FFFFFF''?backgroundColor=''#e489cd'' shadowDirection='''' wordWrap=''true'' horizontalScrollPolicy=''off'' fontSize=''18'' textAlign=''left'' verticalScrollPolicy=''on'' editable=''false'' %26gt;
?
?
%26lt;/mx:TextArea%26gt;

Well, maybe the timer is further interfering with the problem. Try building a test case that doesn't use timer and huge padding values and add the text via a button click and see if the callLater trick is needed and works in that case.

If you look in TextArea, you'll see that it adjusts its scroll properties ''after the fact''. Another thing you could try is two callLaters.

Alex Harui

Flex SDK Developer

Adobe Systems Inc.

Blog: http://blogs.adobe.com/aharui

No comments:

Post a Comment