Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Displaying text in a dynmic text field

Engaged ,
May 16, 2015 May 16, 2015

I'm trying to track the location of the bar (mc_InvestmentButton), set it equal to a percentage, and have it display continuously as the user is moving the slider in a dynamic text field. For example, if the the bar's y position is at 200, the text field should show 5%, if it's at 250 it should show 6%, and so on. I've tried some things but I'm not getting the desired result. See picture for the basic idea. Here is the code:

import flash.display.MovieClip;

import flash.events.MouseEvent;

import flash.events.Event;

import flash.geom.Rectangle;

var sliderBounds: Rectangle = new Rectangle(slider_background_mc.x, slider_background_mc.y, 0, slider_background_mc.height);

mc_InvestmentButton.addEventListener(MouseEvent.MOUSE_DOWN, moveInvestmentButton);

mc_InvestmentButton.addEventListener(MouseEvent.MOUSE_UP, moveInvestmentButtonOFF);

txt_CurrentRate.text = String(mc_InvestmentButton.y);

var displayRate = txt_CurrentRate;

// Your start functions should now be this

function moveInvestmentButton(e: MouseEvent): void

{

    mc_InvestmentButton.startDrag(false, sliderBounds);

    stage.addEventListener(MouseEvent.MOUSE_UP, moveInvestmentButtonOFF);

   

    trace(mc_InvestmentButton.y);

    trace(displayRate);

       

}

function moveInvestmentButtonOFF(e: MouseEvent): void

{

    mc_InvestmentButton.stopDrag();

    stage.removeEventListener(MouseEvent.MOUSE_UP, moveInvestmentButtonOFF);

}

**********************

Here is the basic idea:

rate.PNG

**********************

Here is the trace output data when I clicked on the slicer 3 times:

Capture.PNG

TOPICS
ActionScript
522
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2015 May 16, 2015

Is the text value, 5% for instance, meant to correspond to the values listed on the scroller?

The way that you have this set of functions written, you are adding an event listener that already exists on the mouseDown event and then removing it on the mouseUp event. I don't think that you really want to do either of those things.

If all of the objects are on the main timeline and you want the value in the text box to correspond with the values on the scroll bar, then you need to build an inverse relationship between the y position of the scroll button and the value that you want to show. The baseline for the y, vertical position, property is the bottom of the stage. This is y 0 on the main timeline. So, as you move up, the value increases. However, your example looks like you want to get a smaller value as the position of the button moves up.

Is any of that correct?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 17, 2015 May 17, 2015

I want the value of the text field to equal preset numbers. So for example:

If y = 50 then textfield = 1%

If y = 75 then textfield = 2%

If y = 100 then textfield = 3%

If y = 125 then textfield = 4%

So and so forth, up to 10%. The user can drag the bar to the corresponding values. This is just a test version. Ultimately, I will show how interest can increase over a number of years.

Thanks for your input.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 16, 2015 May 16, 2015

use:

import flash.display.MovieClip;

import flash.events.MouseEvent;

import flash.events.Event;

import flash.geom.Rectangle;

var sliderBounds: Rectangle = new Rectangle(slider_background_mc.x, slider_background_mc.y, 0, slider_background_mc.height);

mc_InvestmentButton.addEventListener(MouseEvent.MOUSE_DOWN, moveInvestmentButton);

mc_InvestmentButton.addEventListener(MouseEvent.MOUSE_UP, moveInvestmentButtonOFF);

txt_CurrentRate.text = String(mc_InvestmentButton.y);

var displayRate = txt_CurrentRate;

// Your start functions should now be this

function moveInvestmentButton(e: MouseEvent): void

{

    mc_InvestmentButton.startDrag(false, sliderBounds);

    stage.addEventListener(Event.ENTER_FRAME,textF);

  

    trace(mc_InvestmentButton.y);

    trace(displayRate);

      

}

function textF(e:Event):void{

your_tf.text=String(mc_InvestmentButton.y);  // use your tf's name/reference.

}

function moveInvestmentButtonOFF(e: MouseEvent): void

{

    mc_InvestmentButton.stopDrag();

    stage.removeEventListener(Event.ENTER_FRAME,textF);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 17, 2015 May 17, 2015
LATEST

Thanks. I will try this approach as well.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2015 May 16, 2015

Try changing to...

function moveInvestmentButton(e: MouseEvent): void
{
    mc_InvestmentButton.startDrag(false, sliderBounds);
    stage.addEventListener(MouseEvent.MOUSE_UP, moveInvestmentButtonOFF);
stage.addEventListener(MouseEvent.MOUSE_MOVE, adjustCurrentRate);
}

function moveInvestmentButtonOFF(e: MouseEvent): void
{
    mc_InvestmentButton.stopDrag();
    stage.removeEventListener(MouseEvent.MOUSE_UP, moveInvestmentButtonOFF);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, adjustCurrentRate);
}

function adjustCurrentRate(evt:MouseEvent):void {
txt_CurrentRate.text =  String(Math.floor(10*(mc_InvestmentButton.y - slider_background_mc.y)/(slider_background_mc.height - slider_background_mc.y)));
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 17, 2015 May 17, 2015

Thanks Ned. I will try it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines