Click the mouse generate number

I'm doing a mouse event that return a random number of a dynamic text box...

When I publish the function that generates the numbers works

but when I call the function with the click of the mouse, it doesn't work.

Could someone help me?

Tnks!

var resultado:Number=sorteio();

function sorteio (): number

{

return Math.round (Math.random () * 500);

}

sorteio();

sorteio_txt. Text = String (result);

my_btn.addEventListener (MouseEvent.CLICK, onClick);

function onClick(e:MouseEvent):void

{

sorteio();

}

To change your original code the less you can replace the sortio with this function. It assigns the new random number to the result variable and then assigns result to the text field.

function sorteio (): number

{

Resultado = Math.round (Math.random () * 500);

sorteio_txt. Text = resultado.toString ();

return result;

}

kglad solution is also very good and works.

In your example, you want a version string of random number. A good design would be keep your variable result recorded under a number and convert it to a string only when you need to display in a text field. In this version, you have result recorded under a variable number and each method does its thing. Everything is a bit more decoupled.

var resultado:Number;

sorteio();

displayResultado();

my_btn.addEventListener (MouseEvent.CLICK, onClick);

function sorteio (): void

{

Resultado = Math.round (Math.random () * 500);

}

function displayResultado (): void

{

sorteio_txt. Text = resultado.toString ();

}

function onClick(e:MouseEvent):void

{

sorteio();

displayResultado();

}

Tags: Adobe Animate

Similar Questions

  • I can't use my keyboard unless I click on tool palette on my second monitor. I'm under 10.10.4 CS6. Basically - once I click the mouse in brush, stamp, etc., I can't cancel, fast replacement of tools, change the size of the brush etc. unless I click on th

    I can't use my keyboard unless I click on tool palette on my second monitor. I'm under 10.10.4 CS6. Basically - once I click the mouse in brush, stamp, etc., I can't cancel, fast replacement of tools, change the size of the brush etc. unless I click on the tool palette. Had this problem for months. Don't know what to do. Going to lose my mind.

    Have you installed the WhiteWindowWorkaround plugin to work around known issues in Mac OS?

  • Click the mouse and drag through the animation of Platinum

    Hi all

    First of all - thank you for taking the time to look through and maybe help me with this question.

    I'm just addressing flash actionscript 3.0 cc - so I apologize in advance for my not so much technical jargon.

    In the past, I used actionscript 1.0 to create an interactive html file containing the animation of a hub of a 3D model. Users can click the mouse and drag to the left or right to 'spin' the model around - however they do really is already through the timeline containing 360 pictures of it from 360 degrees. Similar ideas can be found here: Thyroidectomy Interactive

    Now boring I can't use the old code any more that I work in the latest Flash actionscript 3.0 cc

    So, how I do the same thing but in actionscript 3.0?

    So I worked this piece so far

    On my main stage, I have two layers - Layer actions and another layer with my video (movieclip_mc)

    In the layer actions so far:

    movieclip_mc.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
    movieclip_mc
    .addEventListener(MouseEvent.MOUSE_UP, onMouseUp);


    function onMouseDown(event:MouseEvent):void
    {
      movieclip_mc
    .addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
      //I should put something in here about mouseX  - but no idea what

    }

    function onMouseUp(event:MouseEvent):void
    {
      movieclip_mc
    .removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
    }

    function onMouseMove(event:MouseEvent):void
    {  
    //I have to put something in about total frames - width of movieclip_mc etc but I'm not sure how   

    // this is what someone else did on another forum - but I'm not sure what it means:

         var delta:int = backgroundClip.mouseX - clickedMouseX;
      
    var wantedFrame:uint = (clickedFrame + delta * clip.totalFrames / backgroundClip.width) % clip.totalFrames;
      
    while (wantedFrame < 1)
      
    {  
      wantedFrame
    += clip.totalFrames;
      
    }
      clip
    .gotoAndStop(wantedFrame);
    }

    Also, I think I need something at the beginning as...:

    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    import flash.display.Sprite;

    var clickedMouseX:int;
    var clickedFrame:uint;
    var backgroundClip:Sprite = getChildByName("background") as Sprite;
    var clip:MovieClip = getChildByName("animation") as MovieClip;
    clip
    .stop();
    clip
    .mouseEnabled = false;


    .. but I'm a little confused as to what she means


    So I understand the principle but no idea how to actually make it work - could someone help explain to me or help with the code?

    Thank you very much to all those who can offer help

    Catherine

    I missed replying to your answer yesterday, although I see it - I turned away by another chore for the rest of the day.

    The game of AS2 code that show you closest matches what you do with the AS3 version.  And if you include all its implications and change a little bit, it should work for you.

    Your AS3 onMouseDown function was missing the mouseX code as you mentioned... converting from the AS2 version it would be...

    function onMouseDown(event:MouseEvent):void
    {

    startX = clip.mouseX;

    startFrame = clip.currentFrame;
    movieclip_mc.addEventListener (MouseEvent.MOUSE_MOVE, onMouseMove);
    }

    The onMouseMove function is somewhat a different story because it stops looking like the AS2 version when you transfer the background object in the picture.  If you were to model after the version AS2, you might find that it will work.  The AS2 version can quite easily transformed into AS3 if you use just the following guide...

    "_xmouse' in AS2 becomes"mouseX' in AS3

    "_currentframe" is that as2 becomes "currentFrame" in AS3

    "_totalframes' in AS2 becomes"totalFrames"in AS3

  • Keyboard no longer works in the terminal until I click the mouse in the OSX terminal

    Somehow the last week I have big fingers something while working in a terminal and the keyboard does not show anything when I type until I click on the mouse button.

    I tried the reset command, but it does not solve the problem.

    It's so weird, I don't know even how to describe correctly the problem. It should be easy to understand to describe it, as tonsillitis.

    Well, last week when this happened, I killed and restarted the window. I had a running python script to try to understand what the hijacking of my accent when my accent is hijacked and tried to see if there is anything in what could give me a hint.  Then I went back to the window I tried to reset and it worked again.

    Very confusing. The reset command was perhaps delayed time?

  • Drop-down menus are black boxes, namely:-bookmarks, address in the address bar type, click the mouse on the left. Help

    When I click on my favorites, the menu drops down, and the window is all black. I have to move the mouse around the fall down to to display bookmarks. This happens with the bat address and when I left click on the mouse. I uninstalled firefox and reinstalled, but the problem continues to be.

    Hello, it could be a problem with hardware acceleration. Please try updating your graphic driver (this should be the right version for your system: http://downloadcenter.intel.com/Detail_Desc.aspx?agr=Y & DwnldID = 22375), or in the case where this does not the problem disable hardware acceleration in firefox > options > advanced > General.

  • Hi, I have a problem that only happens in Firefox (under IE does not): when I Middle click the mouse it opens a new tab, but it also grow my Web site to the top of the page &amp; I need to drag all the way back to where I was. Please I need a solution! Th

    When I Middle click with the mouse, it opens a new tab and also pushing my website to the top of the page and it's really annoying when I need to drag all the way back to where I was

    URL of your Web site? And an example of a hyperlink that does this?

  • I can'r open a new tab by clicking on "Open new tab", I can open a new tab by clicking the mouse wheel while

    I to open a new tab by clicking on the + or "open new tab" in the drop down... I can open pages in a new tab by clicking right mouse wheel. I did not make changes to settings.

    Uninstall the Ask Toolbar to Ask published a fix for this problem

  • computor pings when I click the mouse

    When I use the mouse to go back to the my e-mail Inbox, it makes a noise of ping and nothing happens. The screen is locked on an open e-mail.

    Hello

    1. what operating system do you use?

    2. what browser do you use?

    3. What mail client do you use?

    4. this problem only occurs with the e-mail or any other application?

    5. have you made changes on your computer?

    6. who is your provider of mail service?

    You can also visit the link of the article of Microsoft that will guide you on how to ask questions below.

    How to ask a question

    http://support.Microsoft.com/kb/555375

  • Double-click the mouse events to change the display size

    Hello to everyone.

    Thank you very much for reading this post and be able to help.

    I have an image on the screen in front of the Panel.

    I would like that when users double click on it, the display size increases at a specific site for user ca better view.

    How can I do this event?

    Thank you very much.

    Here you can get information about how to create a mouse double click event:
    http://digital.NI.com/public.nsf/allkb/391D522B0FDD4B3F862571E300739F44

  • New version, right click the mouse on a link, don't have choice "Properties"?

    On the old version of Fire Fox, I could right click a link on a web page and one of my options was 'properties', that I would always have this option

    This image is in a frame, you have to look in the menu of the image for the info.

    Properties of the element 6: https://addons.mozilla.org/firefox/addon/14228

  • Click the mouse only opens windows live mail

    I'm trying to help my dad to fix his PC.  It doesn't open Windows mail when you click on anything whatsoever.  We even tried to use the key enter and the same action has occurred.  I'm lost for what to do...

    Hello Eric,

    -Did you do changes on the computer before the show?

    This could be caused due to the Association of files corrupt on the computer.

    I suggest to set defaults to the program to open each file and check to see if that fixes the problem.

    Check out these links to find out how to set the default program Windows uses to open a file.

    Change the programs that Windows uses by default

    Change default programs using Set Program Access and computer defaults

  • I leave my computer on at night, but when I wake up, he seems to be sleeping. Even if I click the mouse or the keyboard I can't use it. I ended up having to turn the disk hard drive off... there must be a setting I can change.

    In addition, I recently did a restore on my computer, but everything else seems to work perfectly.

    I have a windows vista Home premium 64-bit

    Hello

    There are two approaches for this type of problem (usually caused by a device driver that does not support the waking state, gets into the system).

    (1) change your power settings (Control Panel/Power Options/change Plan settings) do not use the State of low power to the hard drive, but rather to put this line to 'never '.

    (2) see if your system BIOS has an option to change the State of sleep and cut in one step (for example from S4 to S3). Good luck, Rick Rogers, aka "Crazy" - Microsoft MVP http://mvp.support.microsoft.com Windows help - www.rickrogers.org

  • The object follows after clicking the mouse

    The title says what I want to achieve.

    My code is as follows:

    package
    {
    import flash.display. *;
    import flash.events. *;
    SerializableAttribute public class Sample extends MovieClip {}
    public void sample (): void {}
    var c:Rreth = new Rreth;
    c.x = 275 Fokker-built;
    CY = 205;
    c.buttonMode = true;
    c.addEventListener (MouseEvent.MOUSE_DOWN, MouseDown);
    addChild (c);
    }
    public void MouseDown(e:MouseEvent):void {}
    c.addEventListener (Event.ENTER_FRAME, moveMyRreth);
    }
    public void moveMyRreth(event:Event):void {}
    var thisRreth:Rreth = (event.target as Rreth);
    thisRreth.x thisRreth.x = - mouseX;
    thisRreth.y thisRreth.y = - mouseY;
    }
    }
    }

    Error thrown is:

    C:\Users\Adi\Desktop\Sample\Sample.as, line 15 1120: access of undefined property c.

    Who can help me get the result I want?

    Your var c is defined in the example service so function MouseDown has no idea what it is. Set outside the function:

    ...
    private var c:Rreth;
    
    public class Sample extends MovieClip {
            public function Sample():void {
                c = new Rreth();
    ...
    
  • How continually increment while the mouse click now

    The attached VI increments a number to each mouse click.  Is it possible to increment permanently with the structure of the event and now the click of the mouse?  For example, if I want to increment the counter from 1 to 100, I don't want to have to click the mouse 100 times, I just want to click once and hold.

    Here's a slightly simplified version which removes some code duplication.

    (Note that both Tim and I have placed before the structure of the event mark.) This eliminates the need for the reset operation).

  • Satellite U500-1E0 - how to turn off the mouse "by clicking on" noise

    Please can someone tell me how to turn off the little "click" the mouse buttons do when they're depressed?

    Thank you.

    Hello

    What rattling noise do you hear?
    The rattling noise which is made by touchpad?
    Is - this mechanical noise or sound comes from the speakers?

Maybe you are looking for