A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: flash cs6 - as3 - enter_frame

  1. #1
    Registered User
    Join Date
    Feb 2015
    Location
    india
    Posts
    2

    Unhappy flash cs6 - as3 - enter_frame

    Hello Everyone

    i m a student of flash & facing a problem in as3

    my code is:-

    import flash.display.Shape;
    import flash.events.Event;

    var star:Shape = new Shape
    addChild (star)
    star.graphics.beginFill(0xe4d00d)
    star.graphics.drawCircle(10,10,2)
    star.alpha=0.8
    stage.addEventListener(Event.ENTER_FRAME,pl)
    function pl(event:Event)
    {
    star.graphics.drawCircle(Math.random()*550, Math.random()*200, Math.random()*3)
    }

    this code generated random dots the way i want but now i don't know how to stop animation when dots reached above 500..

    Somebody Please help me

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    You just need to remove the listener. there are a few ways to do this, but here is one.
    PHP Code:
    import flash.display.Shape;
    import flash.events.Event;

    var 
    j:Number 0;
    var 
    maxDot:Number 500;

    var 
    star:Shape = new Shape();
    addChild(star);

    star.graphics.beginFill(0xe4d00d);
    star.graphics.drawCircle(10,10,2);
    star.alpha 0.8;

    stage.addEventListener(Event.ENTER_FRAME,pl);
    function 
    pl(event:Event)
    {
        
    star.graphics.drawCircle(Math.random() * 550Math.random() * 200Math.random() * 3);
        
    j++;
        
    trace(j);
        if (
    >=  maxDot)
        {
            
    stage.removeEventListener(Event.ENTER_FRAME,pl);
            
    trace("Reached " +  maxDot " now stop.");
        }


  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi

    Or you could simplify it and draw them all instantly, like so.
    PHP Code:
    import flash.display.Shape;
    import flash.events.Event;

    var 
    j:Number 1;
    var 
    maxDot:Number 500;

    var 
    star:Shape = new Shape();
    addChild(star);

    star.graphics.beginFill(0xe4d00d);
    star.graphics.drawCircle(10,10,2);
    star.alpha 0.8;

    while (
    <= maxDot)
    {
        
    star.graphics.drawCircle(Math.random() * 550Math.random() * 200Math.random() * 3);
        
    trace(j);
        
    j++;

    or a do while
    PHP Code:
    do
    {
        
    star.graphics.drawCircle(Math.random() * 550Math.random() * 200Math.random() * 3);
        
    trace(j);
        
    j++;
    } while (
    <= maxDot); 
    Last edited by fruitbeard; 02-25-2015 at 08:11 AM.

  4. #4
    Registered User
    Join Date
    Feb 2015
    Location
    india
    Posts
    2

    it works ... Thanksyou So much fruitbeard :)

    Quote Originally Posted by fruitbeard View Post
    Hi

    Or you could simplify it and draw them all instantly, like so.
    PHP Code:
    import flash.display.Shape;
    import flash.events.Event;

    var 
    j:Number 1;
    var 
    maxDot:Number 500;

    var 
    star:Shape = new Shape();
    addChild(star);

    star.graphics.beginFill(0xe4d00d);
    star.graphics.drawCircle(10,10,2);
    star.alpha 0.8;

    while (
    <= maxDot)
    {
        
    star.graphics.drawCircle(Math.random() * 550Math.random() * 200Math.random() * 3);
        
    trace(j);
        
    j++;

    or a do while
    PHP Code:
    do
    {
        
    star.graphics.drawCircle(Math.random() * 550Math.random() * 200Math.random() * 3);
        
    trace(j);
        
    j++;
    } while (
    <= maxDot); 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center