Skip to main content
Participating Frequently
September 25, 2011
Answered

scrolling event: movieclip instead of dynamic text

  • September 25, 2011
  • 1 reply
  • 771 views

Hello everybody. I am very very novice to actionscript, so probably my question will sound a little silly.

I am trying to put an arabic text to scroll with a custom scrollbar. So I found a nice video in youtube about doing that with a dynamic text field. It works wonderful for latin characters (left to right and separated letters) but unfortunately not for arabic characters (they don't get connected). Actually, I don't care to use just a movieclip with the text instead of the dynamic text field. But I don't know how to change the actionscript code for the movie clip instead of the dynamic text field.

Here I show you the code for the scrolling text in a dynamic text field (it's a short code), on the stage I got just the dynamic text field (instance name: texto_txt), the scrollBar (a vertical line, instance name: scrollBar_mc) and the scroller itself (a little rectangle, instance name:scrollHandle_mc😞

var content:String = "cjeihfirehjfejlkfjkerjfirjfejifjrijwkjfirwjekñlkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkllllllll";

texto_txt.text = content;
texto_txt.wordWrap = true;

var min: Number = scrollHandle_mc.y;

var max: Number = min +(scrollBar_mc.height - scrollHandle_mc.height);

var intervalo: Number = max - min;

var arrastrando: Boolean = false;

var bounds: Rectangle = new Rectangle (scrollHandle_mc.x, scrollHandle_mc.y, 0, scrollBar_mc.height - scrollHandle_mc.height);

scrollHandle_mc.addEventListener (MouseEvent.MOUSE_DOWN, arrastrandoScroll);

stage.addEventListener (MouseEvent.MOUSE_UP, stopIt);

function arrastrandoScroll(mouseEvent:MouseEvent)

{

scrollHandle_mc.startDrag(false,bounds);

arrastrando = true;

scrollHandle_mc.addEventListener(Event.ENTER_FRAME, progress);

}

function stopIt(mouseEvent:MouseEvent)

{

scrollHandle_mc.stopDrag();

arrastrando = false;

}

function progress(e:Event)

{

var moverScroll:Number = scrollHandle_mc.y - min;

var percent:Number = moverScroll/intervalo;

if (arrastrando == true)

{

texto_txt.scrollV = percent * texto_txt.maxScrollV;

}

}

What I want to do is clear the dynamic text field and use instead a movieclip (text_mc) that includes already the text, the bounding box would be a mask. How do I change the actionscript? Could anyone help me out?

This topic has been closed for replies.
Correct answer Ned Murphy

It isn't really a matter of math, as much as it is logical reasoning, but if you plan to do things with programming, you better plan on getting comfortable with learning math as well.  Programming and math go hand-in-hand.

Here's a simplified explanation of what your code needs to do -> If you move the scroller 25% of the total distance it can move, then the movieclip should be moved 25% of the distance it can move (in the oppostie direction).

Your scroller handle can be moved a predefined distance.  In your code that value is called "intervalo".  See if you can figure out how that value is determined in the 3 lines of code.

var min: Number = scrollHandle_mc.y;

var max: Number = min +(scrollBar_mc.height - scrollHandle_mc.height);

var intervalo: Number = max - min;

Later on in your progress function you can see where the scrollbar handle values com into play again when determining where to place the textfield.  But if we change that to be the movieclip, it becomes more like the following...

function progress(e:Event)

{

    var moverScroll:Number = scrollHandle_mc.y - min;

    var percent:Number = moverScroll/intervalo;

    if (arrastrando == true)

    {

         yourMC.y = percent * (yourMCmaxY-yourMCminY) + yourMCMinY;

        // where  yourMCmaxY-yourMCminY is the mc's movement range

        // which is likely to be negative since yMax is likely < yMin for the mc.

   }

}

1 reply

Ned Murphy
Legend
September 25, 2011

You need to rewrite the code to deal with the 'y' property of the movieclip rather than the scrollV property of the textfield.

Just try to realize what the scroller is doing and you should be able to figure it out.  It is taking the percentage of the position of the scrollhandle relative to its full movement range and applying  that ratio to set the scroll property of the textfield to its full scroll range..  So you just want to change that to be setting the y property of the movieclip against its full range per the handle ratio... equation-wise...

handle.y               movieclip.y

------------   =    ----------------

handle range         movieclip range

enteka6Author
Participating Frequently
September 25, 2011

Hello Ned, I am so glad for your reply. Vaguely I guess what you want to tell me but I just don't get how to set it to my actionscript. I am not abled to set it on my own, mathematics are not at all my allies. Something that seems so simple...

Ned Murphy
Ned MurphyCorrect answer
Legend
September 25, 2011

It isn't really a matter of math, as much as it is logical reasoning, but if you plan to do things with programming, you better plan on getting comfortable with learning math as well.  Programming and math go hand-in-hand.

Here's a simplified explanation of what your code needs to do -> If you move the scroller 25% of the total distance it can move, then the movieclip should be moved 25% of the distance it can move (in the oppostie direction).

Your scroller handle can be moved a predefined distance.  In your code that value is called "intervalo".  See if you can figure out how that value is determined in the 3 lines of code.

var min: Number = scrollHandle_mc.y;

var max: Number = min +(scrollBar_mc.height - scrollHandle_mc.height);

var intervalo: Number = max - min;

Later on in your progress function you can see where the scrollbar handle values com into play again when determining where to place the textfield.  But if we change that to be the movieclip, it becomes more like the following...

function progress(e:Event)

{

    var moverScroll:Number = scrollHandle_mc.y - min;

    var percent:Number = moverScroll/intervalo;

    if (arrastrando == true)

    {

         yourMC.y = percent * (yourMCmaxY-yourMCminY) + yourMCMinY;

        // where  yourMCmaxY-yourMCminY is the mc's movement range

        // which is likely to be negative since yMax is likely < yMin for the mc.

   }

}