A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: KM7 differences AS3

  1. #1
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    Exclamation KM7 differences AS3

    As I start looking at tutorials and examples on other sites I'll try to post what I learn regarding the differences between Flash and KM7 AS3

    The first thing you learn in Flash/Flex is that everything must be in a package, this is not the case in KM7 When putting code in the timeline. KM creates the package for you so leave that out..Also you will often see that there must be a MAIN function that is the same name as the function, since we don't create the package we don't create this function either. So here is a simple example of drawing a circle where I've commented out the parts from another tutorial that you don't want.

    PHP Code:
    // package  {

      
    import flash.display.Sprite;

       
    //public class FilledCircle extends Sprite {

    //       function FilledCircle():void {

             
    var circle:Sprite = new Sprite();
             
    circle.graphics.beginFill(0xFF794B);
             
    circle.graphics.drawCircle(505030);
             
    circle.graphics.endFill();
             
    addChild(circle);

      
    //     }
        //}
     //} 
    However if you want to resuse the filledcircle as a CLASS you remove the comments above and put this into a seperate file named FilledCircle.as either in the same directory as you fun file or in the bin/AS3/classes folder then you can create instances of the class

    var t = new FilledCircle();

    addChild(t);

    in the timeline.

    This example is from http://edutechwiki.unige.ch/en/AS3_e...awing_graphics

    Please feel free to add to this thread
    Last edited by blanius; 01-01-2009 at 12:45 PM.

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    Simple button

    KM ships with a great button class, but if you want to use a simple button Flash has this and you can access it.

    The original tutorial is at http://edutechwiki.unige.ch/en/AS3_example_Button

    Here is the KM modified code to put directly in the timeline.

    PHP Code:
     //package {
         
    import flash.display.Sprite;
         
    import flash.text.TextField;
         
    import flash.events.*;
     
       
    //  public class ButtonInteractivity extends Sprite {

             
    var button:Sprite = new Sprite();

          
    //   public function ButtonInteractivity() {
                 
    drawButton()
                 
    button.addEventListener(MouseEvent.MOUSE_DOWNmouseDownHandler);
                 
    addChild(button);
            
    // }
            
            
    function drawButton():void {
                 var 
    textLabel:TextField = new TextField()
                 
    button.graphics.clear();
                 
    button.graphics.beginFill(0xD4D4D4); // grey color
                 
    button.graphics.drawRoundRect(0080251010); // x, y, width, height, ellipseW, ellipseH
                 
    button.graphics.endFill();
                 
    textLabel.text "Click Me!";
                 
    textLabel.10;
                 
    textLabel.5;
                 
    textLabel.selectable false;
                 
    button.addChild(textLabel)
             }

             function 
    mouseDownHandler(event:MouseEvent):void {
                 
    button.+= 20
                 
    if (button.400) { button.0}
             }
         
    //}
     //} 
    Better yet use the original code from that tutorial and save it as ButtonInteractivity.AS in the same directory or in bin/AS3/classes and then try this on your timeline
    Code:
    var b=new Array();
    var h=30;
    for (var x:integer;x<10;x++){
    	b[x]=new ButtonInteractivity();
    	b[x].y=h;
    	addChild(b[x]);
    	h+=30;
    	}
    You can see where this leads as for reusing your code.
    Last edited by blanius; 01-01-2009 at 12:59 PM.

  3. #3
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    KM7 is very similar to the default behaviour of Flash CS3.

    • Both Flash CS3 and KM create a document class automatically by default.
      The difference is that Flash CS3 allows for a custom document class while KM doesn't at this time.
    • Both Flash CS3 and KM use frames you can put a script in.
    • Both Flash CS3 and KM don't require import statements in frame scripts for intrinsic player classes.
    • Both Flash CS3 and KM declare gui created movieclips, buttons and components automatically so you can script them.
    • Both Flash CS3 and KM don't accept things like package, public, private etc. in frame scripts.
    • Both Flash CS3 and KM allow using external packages inside frame scripts using import statements.


    The biggest difference is between Flex on one side and KM and Flash CS3 on the other side.
    Flex doesn't have a frame based IDE where you can set frame scripts. When using Flex, you always have to create a document class yourself.
    When you start with a Flash CS3 example, you probably won't have to change much code. When you start with a Flex example, you have to change some things to make things work.

  4. #4
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Lets talk about classes and how to add them.

    When you create a class or get one from the net you will usually have one or more .as files in a folder. The easiest way to keep track and make it simple to include in you Koolmoves project is to place this folder in the classes folder which is found in koolmoves/bin/as3/classes just save/move your folder with as files to this folder.

    for example lets say you want to use flash-dev's reflection class. It comes in a zip file that has a root folder of flashdev with a subfolder of bitmap. extract this into the classes folder (personally I put mine in the com folder but that's me)

    Now to use this class in your KM project you must know where it is.

    so the first line in you project should look like this
    import flashdev.bitmap.*;

    Since KM already knows where the classes folder is you do not need to include that part of the path, notice though that for each '/' in the path we now use a '.' the '*' tells the compiler to load ALL .as files in that folder.

    You can also put your classes elsewhere if you wish but you should use the pulldown menu in KM to set the class path there so that you do not have to type the entire path everytime.

    NOTE:If you encounter a class file that does seem to work in KM please let support know about it.

  5. #5
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    A little addition, the current project folder is searched first by default so it is also possible to create the directory structure based on the location of the .fun file. That way it is easy to use a particular class for a single project. Especially if you alter an existing class this can be convenient so other projects are not affected by the changes you make.

  6. #6
    Senior Member byweb's Avatar
    Join Date
    Apr 2007
    Location
    Andalucia (spain)
    Posts
    267
    ....... When you start with a Flash CS3 example, you probably won't have to change much code. When you start with a Flex example, you have to change some things to make things work.
    Wilbert sorry but this is not always that way, my personal experience is that what works in CS3, do not always work in KM. I do not know if it is not entirely finished compiler KM, but I try to implement code AS3 that works in CS3 and KM does not work. Now for example I am trying to use the example in KM, SWFAddress and does not work. Then that we are not developers we have complicated too in KM.
    Last edited by byweb; 03-11-2009 at 05:19 AM.

  7. #7
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Document classes and third party classes developed for CS3 are still a problem at this time.
    Bob is constantly working on improving the compiler but the AS3 language is so complex that it is almost impossible to get 100% success from the start. You probably will notice that with new updates more and more classes will work without adaptations.
    Chris has a page on www.km-codex.com with classes that are confirmed to work with the most recent KM version.

    Edit: Document class is supported from KM 7.0.3
    Last edited by w.brants; 03-18-2009 at 12:45 PM.

  8. #8
    Senior Member byweb's Avatar
    Join Date
    Apr 2007
    Location
    Andalucia (spain)
    Posts
    267
    Wilbert Thanks for your explanation, I do not know what was so complicated to make a compatible compiler. I've grown accustomed to working with KoolMoves, and all my web projects are done with this tool, with the advent of AS3, I thought we would at CS3 and there was no distinction then, I thought it was important to the script.
    I do not claim that KM is a clone of CS3, I like KM more. I am now starting to learn AS3, this I bought a book of AS3 code and believed he could practice with KoolMoves.
    I wonder a lot here and in the forum Necromanthus and always find help, I appreciate much, but sometimes I think I am annoyed with so many questions and I try to create for myself, learning AS3 and despair when they do not work.
    I try to do like Chris, KoolMoves adapt classes to understand that we must learn to program, so look for classes that are not complex but not always with success . Thanks.

  9. #9
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Our compiler is young and growing more mature each build. What does not work today may work fine in the coming months.

    The only classes we are trying to add to my site right now are ones which require no major alterations to work with KM7. If we alter a class or waste time trying to make any one function, improvements to the KM compiler may render those changes unneeded down the road and just creates more work trying to force the cart in front of the horse IMO.

    I got your post on SWFAddress in my forum. I posted some food for thought as a reply in the meantime.

  10. #10
    Junior Member
    Join Date
    Aug 2005
    Posts
    17
    Quote Originally Posted by blanius View Post
    Lets talk about classes and how to add them.

    When you create a class or get one from the net you will usually have one or more .as files in a folder. The easiest way to keep track and make it simple to include in you Koolmoves project is to place this folder in the classes folder which is found in koolmoves/bin/as3/classes just save/move your folder with as files to this folder.

    for example lets say you want to use flash-dev's reflection class. It comes in a zip file that has a root folder of flashdev with a subfolder of bitmap. extract this into the classes folder (personally I put mine in the com folder but that's me)

    Now to use this class in your KM project you must know where it is.

    so the first line in you project should look like this
    import flashdev.bitmap.*;

    Since KM already knows where the classes folder is you do not need to include that part of the path, notice though that for each '/' in the path we now use a '.' the '*' tells the compiler to load ALL .as files in that folder.

    You can also put your classes elsewhere if you wish but you should use the pulldown menu in KM to set the class path there so that you do not have to type the entire path everytime.

    NOTE:If you encounter a class file that does seem to work in KM please let support know about it.

    Hi,I've read many of your posts over the years and I'd say your a bit of an expert on koolmoves.
    I attempted to load a Class,placing it C:\Program Files\KoolMoves\Bin\AS3\Classes\classname
    It loaded in the Class editor,but when I went to error check it gave the following "can't find package path",does this mean that the class may not work with Koolmoves? or have I missed something? thanks

    Using Koolmoves Version 7.0.3 AS3
    Last edited by hittingrabbit; 03-27-2009 at 10:18 PM.

  11. #11
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    I think if you have it in the Classes Folder you don't need to add the path there

    did you import it in the Actionscript?

  12. #12
    Super Moderator
    Join Date
    Jun 2000
    Posts
    3,512
    A class where you put it would have no package name. What is the name of the package for the class you created?

    I think it would be better form to created your own folder for the classes you are adding rather than mix your classes with Koolmoves distributed classes.

  13. #13
    Junior Member
    Join Date
    Aug 2005
    Posts
    17
    Quote Originally Posted by blanius View Post
    I think if you have it in the Classes Folder you don't need to add the path there

    did you import it in the Actionscript?

    Your right it's in the classes folder,and yes I used the action script classes/open class editor.....


    Quote Originally Posted by Bob Hartzell View Post
    A class where you put it would have no package name. What is the name of the package for the class you created?

    I think it would be better form to created your own folder for the classes you are adding rather than mix your classes with Koolmoves distributed classes.
    Hi,It's in it's own folder within the classes folder.....
    C:\Program Files\KoolMoves\Bin\AS3\Classes\reflect_V.2.0\asce nsionsystems\mirror
    Last edited by hittingrabbit; 03-28-2009 at 03:52 PM. Reason: not saving correctly it's spacing the letters?

  14. #14
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    I think the dots in the file path are going to be a problem.

    Also you must use:
    Import path.to.class.className in the actionscript

  15. #15
    Junior Member
    Join Date
    Aug 2005
    Posts
    17
    Quote Originally Posted by blanius View Post
    I think the dots in the file path are going to be a problem.

    Also you must use:
    Import path.to.class.className in the actionscript

    That's what it it appear's to have been,once I removed it and made a few other changes it checked ok.....thanks so much for the help,also once I try it out and if it works ok I'll update the status so that the class may be added to KM compatable area.

  16. #16
    Senior Member etuom's Avatar
    Join Date
    Sep 2006
    Location
    Minnesota
    Posts
    193
    Both Flash CS3 and KM don't require import statements in frame scripts for intrinsic player classes.

    Both Flash CS3 and KM don't accept things like package, public, private etc. in frame scripts.
    revised from Bret's example above:
    Code:
    //package {
         /*import flash.display.Sprite; 
         import flash.text.TextField;
         import flash.events.*;*/
    
       //  public class ButtonInteractivity extends Sprite {
    
             var button:Sprite = new Sprite();
    
          //   public function ButtonInteractivity() {
                 drawButton()
                 button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
                 addChild(button);
            // }
            
            function drawButton():void {
                 var textLabel:TextField = new TextField()
                 button.graphics.clear();
                 button.graphics.beginFill(0xD4D4D4); // grey color
                 button.graphics.drawRoundRect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipseW, ellipseH
                 button.graphics.endFill();
                 textLabel.text = "Click Me!";
                 textLabel.x = 10;
                 textLabel.y = 5;
                 textLabel.selectable = false;
                 button.addChild(textLabel)
             }
    
             function mouseDownHandler(event:MouseEvent):void {
                 button.x += 20
                 if (button.x > 400) { button.x = 0}
             }
         //}
    //}
    I thinks it's coming together


    Both Flash CS3 and KM allow using external packages inside frame scripts using import statements.
    So when it comes to the km classes we need to import those because they are an external package?

    As for the flash intrinsic player classes would it be desirable to import them to exclude any unnecessary classes?

    Both Flash CS3 and KM don't accept things like package, public, private etc. in frame scripts.
    But need to be present when scripting your own class and saving as can be seen when looking at the code in the km components?
    Last edited by etuom; 08-07-2009 at 12:14 PM.

  17. #17
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Quote Originally Posted by etuom
    Now when it comes to the km classes we need to import those?
    If you use them in an external class the answer is yes.
    If you use them in a frame script, it depends on the preferences. If you go to [File] > [Preferences] and click the Scripting tab, there are a number of checkboxes that control if the packages that are checked there are automatically imported.

    Quote Originally Posted by etuom
    As for the flash intrinsic player classes would it be desirable to import them to exclude any unnecessary classes?
    You only have to import intrinsic classes in external classes. In a frame script it isn't required.

    Quote Originally Posted by etuom
    But need to be present when scripting your own class and saving as can be seen when looking at the code in the km components?
    That's right
    Last edited by w.brants; 08-07-2009 at 12:21 PM.

  18. #18
    Senior Member etuom's Avatar
    Join Date
    Sep 2006
    Location
    Minnesota
    Posts
    193
    Hey Wilbert! I was editing while you were posting

  19. #19
    Member
    Join Date
    Dec 2005
    Location
    Utah
    Posts
    98
    What's the latest on supporting external document classes? I'm doing far more pure AS3 with the IDE for components and internal classes. I'd love to build the KM document library with the components, sounds, etc. in use, then point KM to an external .as file for compiling.

  20. #20
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    As far as I know document classes have been supported for a long time.
    Can you be more specific what the problem is ?

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