Skip to main content
Participant
January 14, 2016
Answered

class as3 to normal

  • January 14, 2016
  • 1 reply
  • 666 views

Hi!, sooo anyone knows how to change as3 from a class file to normal? (on stage not on a .as file)

This is the class file:

package

{

    import flash.display.Sprite;

    import fl.events.SliderEvent;

    public class Main extends Sprite

    {

        public function Main():void

        {

            //Listen for slider movement

            slider.addEventListener(SliderEvent.CHANGE, changeFPS);

        }

        private function changeFPS(e:SliderEvent):void

        {

            //Change the frame rate using the slider value

            stage.frameRate = e.value;

        }

    }

}

Taken from this guy: (ALL RIGHTS OF HIM)

http://code.tutsplus.com/tutorials/quick-tip-change-the-frame-rate-at-runtime-using-actionscript-3--active-6967

This topic has been closed for replies.
Correct answer robdillon

Nope. mmmm maybe something's missing?


OK, you're being much too cryptic in your responses. Here's a small change to your original code, this may work better for you.

In this version the event listener is added without calling a function.

------------

import flash.display.Sprite;

import fl.events.SliderEvent;

slider.addEventListener(SliderEvent.CHANGE, changeFPS);

      

function changeFPS(e:SliderEvent):void

        {

            //Change the frame rate using the slider value

            stage.frameRate = e.value;

        }

--------------

1 reply

robdillon
Participating Frequently
January 14, 2016

I think this is what you're asking about.

----------

import flash.display.Sprite;

import fl.events.SliderEvent;

         function Main():void

        {

            //Listen for slider movement

            slider.addEventListener(SliderEvent.CHANGE, changeFPS);

        }

        function changeFPS(e:SliderEvent):void

        {

            //Change the frame rate using the slider value

            stage.frameRate = e.value;

        }

---------------

Essentially you need to remove the class definition and the enclosing curly braces. Then you need to remove any "public" or "private" declarations on the functions and/or variables.

Finally, you will need to call the initial function from somewhere.

Participant
January 15, 2016

Well no errors BUT it doesn't work, the slider doesn't change the frame rate on the go.

robdillon
Participating Frequently
January 15, 2016

Do you call the function Main(); somewhere? If you did, try adding a trace command in the changeFPS() function to see if the function is ever called.