Converting onClipEvent (enterFrame) to Actionscript 3

I have an old FLA from another designer ca. 2009 or so written with Actionscript 2.0. I've been successful in converting most of it to Actionscript 3.0 to be published in HTML5 except this one function attached to a sprite which changes the transparency of the movie clip based on mouse proximity. I haven't used Flash much in recent years so any help is greatly appreciated!
onClipEvent (enterFrame)
    pointAtWhichAlphaReaches0 = 200;
    hyp = Math.sqrt(_xmouse * _xmouse + _ymouse * _ymouse);
    setProperty("", _alpha, 100 - hyp / pointAtWhichAlphaReaches0 * 100);
    updateAfterEvent(mouseMove);

attached to that object's timeline (which is poor coding):
var pointAtWhichAlphaReaches0:int=200;
var hyp:Number;
this.addEventListener(Event.ENTER_FRAME,f);
function f(e:Event):void{
    hyp = Math.sqrt(mouseX * mouseX + mouseY * mouseY);
this.alpha=100 - hyp / pointAtWhichAlphaReaches0 * 100;

Similar Messages

  • AS1/AS2 to AS3 onClipEvent(load),onClipEvent(enterFrame)

    onClipEvent (load) {
         total = _root.getBytesTotal();
    onClipEvent (enterFrame) {
         loaded = _root.getBytesLoaded();
         percent = int(loaded/total*100);
         text = percent+"%";
         gotoAndStop(percent);
         if (loaded == total) {
              _root.gotoAndPlay(2);
    Dear all,
    I found a sample code that is writen in AS1/AS2 to see if the load is finished, If finish loading, it will go to the next frame. How do I convent this into AS3? This is my first time looking at AS1/AS2 code, especially onClipEvent (load), _root.getBytesTotal(), onClipEvent (enterFrame), _root.getBytesLoaded(),_root.gotoAndPlay(2).
    Can someone help me out with this?
    Thanks,
    -Zainuu

    Hi, Thanks for the reply
    stop();
    this.addEventListener(Event.ENTER_FRAME, loading);
    function loading(e:Event):void{
        var total:Number = this.stage.loaderInfo.bytesTotal;
        var loaded:Number = this.stage.loaderInfo.bytesLoaded;
         trace(total);
         trace(loaded);
        if (total == loaded){
            play();
            mc_Loader.visible=false;
            this.removeEventListener(Event.ENTER_FRAME, loading);
    I tried to trace the total bytes and loaded bytes, it returns me
    total = 405668
    loaded = 405668
    Is there a way to show the loaded bytes starting from 1 till 405668? I'm trying to find out if it is really loading the thing. Otherwise is there any other ways to slow down the loading for a bit because it only shows my loading bar for 0.5secs, not really sure if its really loading it...

  • Converting MXML Components to ActionScript Classes

    I'm in the process of converting most (if not all) of my MXML
    components to Action Script classes. I've found this is easy, and
    doesn't require a lot of extra code when extending a simple
    container or control. However, several of my MXML components have
    several nested containers and controls - i.e. a component that
    contains several Labels, a ComboBox, a TextInput, a Button, and a
    DataGrid, plus several other containers needed for layout. To code
    the layout of all these containers and controls using MXML, it uses
    about 16 lines of code. To code the layout in ActionScript, it
    takes about 50+ lines of code (see attached).
    I'm just wondering if there are any best practices for
    creating ActionScript classes that include several (or even A LOT
    OF) containers and controls. It's very easy to layout in MXML, and
    is more visibly pleasing to look at and understand, but I feel it
    is best practice to code components as ActionScript classes. I know
    I should be using MVC, but it's a little late to rewrite the entire
    application now.
    Any thoughts?

    I can't specifically speak to how to write layout code in
    ActionScript, but you can look at the generated code that Flex
    creates to get an idea of how Flex does it. When you compile an
    app, the Flex compiler takes your MXML input and converts it to
    ActionScript classes before compiling the entire set of classes
    into a SWF. Because of this, you can look at the interim
    ActionScript code.
    You do this by setting the keep-generated-actionscript
    compiler option to true and looking in the /generated directory.
    hth,
    matt horn
    flex docs

  • Software for convert Filter Presets to ActionScript Code

    This software convert filter presets in Flash 8, CS3 and CS4
    to ActionScript code...
    Very Fast and Usseful...
    http://www.astrodreams.com/flashfilterpresets/convert_flash_filters_presets_to_actionscrip t117release.rar

    that's the easy way. just load the bitmap into the library
    and reference it. but my client needs the entire app to rely upon
    code only, no timeline or library references. so i need to recreate
    the line art of the bitmap of a grab icon into graphics api.
    wondering if there's an easy convert of a bitmap to graphics api
    actionscript code or do i have to just do it by hand which would be
    a pain.

  • OnClipEvent (enterFrame) problem

    Hello all! Long time no see. I am having a problem with a
    current game that i am developing in flash. The problem is that I
    have a movieclip and I want to update the position of one object
    everytime, on a loop. The code is in the end of the message. Every
    function inside that event is called once, but the horseRun() is
    called twice on the same frame and it is updating the object
    position twice.
    How do I fix it?
    See ya!
    Augusto

    Finding it a bit hard to understand the code ... are you
    missing a set of curly braces or an equals sign after the
    if(!finish) ? If it's an = sign it should be horseRun without the
    brackets:
    if(!finish) = horseRun;
    And are AI_horseRun() and horseRun() different?

  • Preloader Problem in Flash MX

    Ok, welcome back again...
    I must first say... this site is perfect... Solving my
    day-2-day Flash mess ups! Ahh, but let us begin!
    I've just created a site (more of an Intro to the site),
    using Flash and I also created a preloader because of the long wait
    before any Flash is actually shown. Unfortunately, I'm getting a
    error message when I preview the movie about the preloader... Let
    me show you the message:
    **Error** Scene=Scene 1, layer=preloader, frame=1:Line 1: Clip
    events are permitted only for movie clip instances
    onClipEvent (enterFrame) {
    Total ActionScript Errors: 1 Reported Errors: 1
    I think it may be important to point out that I have about...
    Twenty-three layers (That span to about 400+ frames) for that movie
    and the preloader layer as the twenty-fourth... Not sure if it's
    positioning with the layers affects the script... Ahh! Speaking of
    script, let me post the ActionScript that's in the preloader's
    first frame:
    onClipEvent (enterFrame) {
    _root.stop();
    mctotal = _root.getBytesTotal();
    mcloaded = _root.getBytesLoaded();
    percent = Math.round((mcloaded/mctotal)*100);
    load = percent+"%";
    progress_mc1._xscale = percent;
    if (percent == 100) {
    _root.play();
    I hope that's all the information that is needed for this
    question to be answered...
    Thanks in Advance!
    -Keno2500

    quote:
    Originally posted by:
    keno2500
    **Error** Scene=Scene 1, layer=preloader, frame=1:Line 1: Clip
    events are permitted only for movie clip instances
    onClipEvent (enterFrame) {
    Total ActionScript Errors: 1 Reported Errors: 1
    -Keno2500
    Well, I am total amateur in actionScript, but if it tells you
    "Clip events are permitted only for movie clip instances", it would
    mean to me, your preloader is not a movie clip. You need to change
    instance propertys for preloader... My head is spinning now, need
    to lay down
    Good luck!

  • Kirupa snow tutorial problems

    I'm new to Flash, but i really can't get the snow 2.0 (
    http://www.kirupa.com/developer/mx2004/snow.htm)
    tutorial to work. i've tried the snow 3.0 (
    http://www.kirupa.com/developer/flash8/snow.htm)
    one without any problems - but I get this error message when I try
    the 2.0 one:
    **Error** Symbol=snow, layer=Layer 1, frame=1:Line 1: Clip
    events are permitted only for movie clip instances
    onClipEvent (load) {
    **Error** Symbol=snow, layer=Layer 1, frame=1:Line 16: Clip
    events are permitted only for movie clip instances
    onClipEvent (enterFrame) {
    Total ActionScript Errors: 2 Reported Errors: 2
    when i test the movie, flash also tells me it's taking too
    long and if i continue my computer may become unresponsive?
    anyone else have similar problems with this tutorial? (I'm
    using flash 8 professional)

    do you have a really old mac? i have tried that source file
    and on my pc never get tht error - it's
    a well known error that signifies a loop script that is too
    processor intensive. I am not sure what
    to tell you because i can not reproduce this - it may be a
    hardware limitation on your mac - try
    uploaded your files and proved a url for everyone here to
    test.
    ~~~~~~~~~~~~~~~~
    --> Adobe Certified Expert
    --> www.mudbubble.com
    --> www.keyframer.com
    ~~~~~~~~~~~~~~~~
    swedemily wrote:
    > ok, so i went through the source flie and found where i
    was making a mistake
    > (it wasn't so much that i hadn't followed the directions
    exactly, but that i
    > don't know enough about flash to realize what the author
    truly meant by some of
    > the directions). anyway, when i test my movie i no
    longer get the error
    > messages, however I do still get the message:
    >
    > "A script in this movie is causing Adobe Flash Player 9
    to run slowly. If it
    > continues to run, your computer may become unresponsive.
    Do you want to abort
    > the script?"
    >
    > When I click "no," I just see the rainbow pinwheel
    spinnin' around for several
    > seconds, then the same message pops up. When I click
    yes, all I see is my
    > background and a tiny, static snow flake in the upper
    left hand corner.
    >
    > What makes a script cause flash player to run slowly? Is
    there perhaps just
    > some setting I need to change somewhere?
    >

  • Converting Actionscript 1.0 to 2.0 in Flash 8

    Hi there,
    Currently, I am developing game using Flash MX which i using
    Action Script 1.0. However, I have install Flash 8.
    My question is, how am I to convert the my previous
    actionscript 1.0 to actionscript 2.0 in Flash 8?
    Thanks.

    most of it should be done by flash when you open your a.s.
    1.0 scripted swf in flash 8 that has publish settings for a.s. 2.0.
    some of it you'll need to do by hand, though.

  • Questions about this snippet of preloader ActionScript

    I'm working on a flash template that uses the following code for its preloader.
    onClipEvent (load) {
        total = _root.getBytesTotal();
    onClipEvent (enterFrame) {
        loaded = _root.getBytesLoaded();
        percent = int(loaded/total*100);
        text = percent+"%";
        gotoAndStop(percent);
        if (loaded == total) {
            _root.gotoAndPlay(2);
    2 things about it that I can't figure out:
    The variable 'total' was created inside the first block of code, yet how is it being accessed from the second block of code?  Wouldn't there be a variable scope issue there?
    Also, in the 2nd block of code, when viewing the actual script in Flash, the variable 'text' is highlighted in blue indicating that it is a keyword or something.  And the dynamic text field that's supposed to be connected to the value of the variable 'text' [percent + "%"] is simply named 'z', not 'text'.  Yet the whole thing still works fine.  Don't understand how.
    Thanks,
    David

    Yeah, weird stuff.  Not sure why or how this worked, and I just don't care anymore.  Sloppiest code I've ever seen :\.  I decided to just publish the file in AS3 and whatever works I'll leave in and what doesn't I'll replace.  I guess it's mostly any code that's attached to objects.  I also got the following message in the output tab as well which points out exactly what I was talking about with this text field...
    WARNING: Text field variable names are not supported in ActionScript 3.0. The variable 'text' used for the text field 'z' will not be exported.
    Good riddance to this mess of code.

  • Action script 3 onClipEvent

    i was reading a tutorial for a little game and when ever i
    try to run it, i get the error " 1087: Syntax error: extra
    characters found after end of program. onClipEvent (enterFrame) { "
    the code is:
    onClipEvent (enterFrame) {
    if (Key.isDown(Key.LEFT)) {
    _x--;
    if (Key.isDown(Key.RIGHT)) {
    _x++;
    if (Key.isDown(Key.UP)) {
    _y--;
    if (Key.isDown(Key.DOWN)) {
    _y++;
    it seems to work for everyone else. Your help is greatly
    appreciated.

    if you're using as 3, there's is no onClipEvent() and there
    is no code that can be attached to an object. read the help files,
    programming with actionscript 3.

  • Actionscript Slideshow horror!!!

    Hey everyone,
    I've got a simple random actionscript slideshow that loads
    external jpgs into a mc. Everything works good but i can't get the
    darn jpgs to fade in and out. Could someone please help, the
    deadline approaches.
    Here is the AS for the movieclip, it's in the 1st frame:
    mc = function() {
    num = (Math.round(Math.random()*2));
    // 50 being the number of your jpg, rename them from 0.jpg to
    49.jpg
    totalfilename = num + ".jpg";
    picLoader.loadMovie("
    http://www.venture-multimedia.com/factory/flash/"
    + totalfilename);
    // _root.picLoader being an empty movie clip instance name
    picLoader, just rename it to watever is
    //your movieClip name and rename the address of your site and
    folder where your images are
    mc();
    // If you want them to come on an interval of 20 seconds
    clearInterval(mc.intID);
    mc.intID = setInterval(mc, 3000);
    An here is the AS for making it fade in and out. This is applied
    to the mc itself:
    onClipEvent (load)
    this._alpha = 0;
    onClipEvent (enterFrame)
    if (this._alpha < 100)
    this._alpha = this._alpha + 5;
    } // end if
    if (this._alpha >= 100)
    this._alpha = 100;
    } // end if
    Thanks for your help!

    So the end of this message got cut off
    I'm wondering how to get the images to fade on ans opposed to
    just showing up?
    Thanks:
    Graphic Graeme

  • Actionscript 1 to 2 button reverse

    Hey guys, i found some nice code on AS1 to use with my Button and MC.
    Basically
    the MC doesnt play when mouse is not on button
    when mouse over button i want the MC to play. (only once then stop)
    when mouse off button i want the MC to play in reverse. (and stop when its back to the beginning)
    (btw both the MC and Button are in a movie clip - as i need to make many of them)
    the code is in AS1 and doesnt seem to work in AS2 which is where i need it.
    Maybe someone can see whats wrong and convert parts for me or give me a new code
    code for button:
    on (rollOver) {
    mc1.goBack = false;
    mc1.play();
    on (rollOut) {
    mc1.goBack = true;
    code for MC:
    onClipEvent (enterFrame) {
        this.rewind();
    code for actions layer:
    MovieClip.prototype.rewind = function () {
    if (goBack && (_currentframe>1)) {
    gotoAndStop (_currentframe-1);
    thanks i really need this code!!!! appriecate any1s help =)

    remove code from your button and assign your button an instance name, say btn:
    btn.onRollOver=function(){
    mc1.onEnterFrame=function(){
    this.nextFrame();
    if(this._currentframe==this._totalframes){
    delete this.onEnterFrame;
    btn.onRollOut=function(){
    mc1.onEnterFrame=function(){
    this.prevFrame();
    if(this._currentframe==1){
    delete this.onEnterFrame;

  • Snow falling: pls help with actionscript

    Hallo,
    I made a flash movie with snow  falling from the sky in Flash 8 (actionscript 2.0)
    However, the snow I made differs  from the original.
    The original is here:
    http://www.kirupa.com/developer/mx/snow.htm
    I  put mine here:
    http://toetssite.webs.com/
    You  will notice that my snow only falls downward: there is no randomness  for the flakes to go left or right. there is no movement.
    WHere  in the script below can I change that so that there's more movement for  the flakes? Thank you
    I use  the following script for the snow itself:
    onClipEvent (load) {
         //specifies the size of the movie stage
         movieWidth = 300;
         movieHeight = 200;
         //variables that will modify the falling snow
         i = 1+Math.random()*2;
         k = -Math.PI+Math.random()*Math.PI;
         //giving each snowflake unique characteristics
         this._xscale = this._yscale=50+Math.random()*100;
         this._alpha = 75+Math.random()*100;
         this._x = -10+Math.random()*movieWidth;
         this._y = -10+Math.random()*movieHeight;
    onClipEvent (enterFrame) {
         //putting it all together
         rad += (k/180)*Math.PI;
         this._x -= Math.cos(rad);
         this._y += i;
         if (this._y>=movieHeight) {
             this._y = -5;
         if ((this._x>=movieWidth) || (this._x<=0)) {
             this._x = -10+Math.random()*movieWidth;
             this._y = -5;
    and on the first frame of my movie I put the following:
    for (k=0; k<50; k++) {
        duplicateMovieClip(this.snow,  "snow"+k, k);
    Thank  you!

    Just initialize the rad variable. I added following line to your code and it works fine.
         rad = 0; //line I inserted.
    No other change required. It is advised to initialize all your variables before you use them.
    Anyways, below I am providing the whole script for the snow after modification
    onClipEvent (load) {
    //specifies the size of the movie stage
    movieWidth = 300;
    movieHeight = 200;
    rad = 0; //line I inserted.
    //variables that will modify the falling snow
    i = 1+Math.random()*2;
    k = -Math.PI+Math.random()*Math.PI;
    //giving each snowflake unique characteristics
    this._xscale = this._yscale=50+Math.random()*100;
    this._alpha = 75+Math.random()*100;
    this._x = -10+Math.random()*movieWidth;
    this._y = -10+Math.random()*movieHeight;
    onClipEvent (enterFrame) {
    //putting it all together
    rad += (k/180)*Math.PI;
    this._x -= Math.cos(rad);
    this._y += i;
    if (this._y>=movieHeight) {
    this._y = -5;
    if ((this._x>=movieWidth) || (this._x<=0)) {
    this._x = -10+Math.random()*movieWidth;
    this._y = -5;

  • Converting AS2 to AS3 Please!

    Hi guys.
    I having a major problem in trying to convert an old AS2 code into AS3.
    It would be great if you guys could help in anyway you can.
    onClipEvent (enterFrame)
        this;
        if (_x > 520)
            setProperty(this, _x, -20);
        } // end if
        this;
        if (_x < -20)
            setProperty(this, _x, 520);
        } // end if
        setProperty(this, _x, _x + Number(1.250000E+000));

    In the timeline of the object in question, try:
    addEventListener(Event.ENTER_FRAME, moveX);
    function moveX(evt:Event):void {
        if(x > 520){
             x = -20;
        if(x < -20){
             x = 520;
        x += 1.25;

  • Help converting AS2 rollover buttons to AS3

    This is probably a really dumb question, but I'm very new to AS3 so please bear with me. I created some rollover buttons (movieclips) for a flash website in AS2 using the following code:
    onClipEvent (enterFrame) {
        this.onRollOver = function() {
        this.gotoAndPlay(1);
    onClipEvent (enterFrame) {
        this.onRollOut = function() {
        this.gotoAndStop(1);
    on (release){
        getURL("index.html", "_parent");
    Could anyone advise me on how to start converting this code into AS3? I know I have to use an EventListener but I don't really understand how it works.
    Any assistance would be greatly appreciated!

    I have changed my code to:
    Link1.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
    Link1.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
    Link1.addEventListener(MouseEvent.CLICK, onClick);
    function onMouseOver(e:MouseEvent):void {
            Link1.gotoAndPlay(1);
    function onMouseOut(e:MouseEvent):void {
              Link1.gotoAndStop(1);
    function onClick(e:MouseEvent):void {
            Link1.navigateToURL(new URLRequest("index.html"), "_parent");
    But it still doesn't work very well. The animation for the rollover keeps playing over and over, ignoring the "stop" I have within the frame of the movieclip.
    You can view my website at: http://www.halopantryandgrill.com/test/index.php to get an idea of how my rollovers worked before. This was done in AS2.
    I can't seem to get the same effect to work in AS3

Maybe you are looking for

  • Error in Installing Jdev 12C through Generic istaller

    I tried to run the installer. it runs and in the middle i gives an error in copying files. You can view the screen shot of the error here . https://docs.google.com/file/d/0B2uF0CGt8hayWUFRSkpDOHU1NGc/edit?usp=sharing

  • FavoriteFolder, how to get the content inside this folder

    Hi I have to get with the Java api consumer the content inside the favorite folder. How can i get it? i write this code:                String searchQuery = search://{'guaglanto1'}?SearchKeywords=true&SearchExact=true&SearchCaseSensitive=true;       

  • I can see the thumbnail, but the picture isn't there!!!

    Hi! I need some help!!! I have been having issues with my camera on my iPhone 4S. I'll take a picture, it'll show up as a thumbnail, but when it's enlarged, the picture is just blank-white. I thought maybe my app was just acting up, but I uploaded th

  • CCMS Monitor for SMTP-Service via ICM SMTP-Plugin

    Dear all, we configured our SAP System for sending emails with the help of transaction SCOT. We are using the SMTP-Plugin brought in by the ICM. Everything works fine. Now we want to report how many emails are sent through that connection. For that w

  • Unknown error -12894 when I try to play a movie rental

    I bought a movie rental to watch while I was on the road.  When I tried to play it on the plane however it would not play and I got this error message: The operation could not be completed. An unknown error occurred (-12894) I have tried to play it a