A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Trying to learn Classes

  1. #1
    Senior Member
    Join Date
    Jun 2002
    Posts
    400

    Trying to learn Classes

    So for 2012 I'm trying to work smarter by using Classes. I've used Flash before and usually just throw all my AS in the actions panel each time. I get that I'm missing out so I'm trying to learn Classes. I've done a handful of basic tutorials and am working on my first self-built Class and can't get it to work.

    So in my .fla I have this...

    Actionscript Code:
    import CalculatePercentageClass;

    And in my CalculatePercentageClass.as (in the same directory as the .fla) I have...

    Actionscript Code:
    package  {
       
        public class CalculatePercentageClass {

            public function CalculatePercentageClass()
            {
                trace("CalculatePercentageClass LOADED");
            }

            public function CalculatePercentage(percent,total):String
            {
               
                public var percent:Number = Number(percent);
                public var total:Number = Number(total);
           
                if (percent > 1)
                {
                    percent = percent/100;
                }
               
                return String(total*percent) + "%";
               
            }

        }
       
    }
    Now, I'm assuming there's quite a bit wrong here but since this is my very first class.

    First, my constructor should be tracing when it loads, correct? I get no compile errors.

    If anybody can see I'm heading down the wrong path on anything, please chime in.

    I realize I'm not using the actual calculatePercentage method yet, I'm just trying to get some proof that it's loading correctly.

    Thanks in advance!
    -Layne

  2. #2
    Senior Member
    Join Date
    Jun 2002
    Posts
    400
    Figured out that I need to link to my Class in the properties panel.

    Also figured out that my Class needs to extend MovieClip.

    So the trace shows up fine now... moving on.

    Should this thread be in the AS3 forum?

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