Développement web indépendant à Montpellier

Publié le mardi 07 avril 2009 14:54:18

Créer une classe en Actionscript 3 (POO)

Cet article s'adresse aux développeurs ayant déjà des notions de programmation orientée objet (POO), et explique la création une classe Actionscript, et l'attachement à un élément de la bibliothèque Flash.

Actionscript 3 est de manière naturelle un langage orienté objet, ce qui offre de nombreuses possibilités en terme de conception et d'énormes facilités en terme de développement; aussi, on peut prendre n'importe quel MovieClip de notre scène Flash, l'attacher à une class Actionscript et le manipuler dans le code.

Les fichiers de classe Actionscript (extension .as)

Vous conviendrez facilement qu'externaliser le code est beaucoup plus confortable pour les développeurs de toutes sortes. Depuis Actionscript 3, on peut attacher une classe Actionscript (fichier .as) à un document entier (.fla, .swf). Mais on a toujours pu attacher des classes à des clips pour les personnaliser et les manipuler.

Création du fichier Actionscript (.as)

Il existe un outil de développement gratuit et extrêmement puissant pour Actionscript : Flashdevelop. Si vous ne disposez pas encore de ce logiciel, je vous conseille d'aller le télécharger directement sur le site officiel de Flashdevelop. Bien que gratuit, il va vite vous faire oublier l'éditeur natif de Flash : vous disposerez ainsi de fonctionnalités bien pratique : complétion, organisation des import, gestion de projets (pour AS2 et AS3).

Une fois installé, créez une nouvelle classe MaClasse qui étendra la classe MovieClip. cela donnera ceci :

package 
{
    import flash.display.MovieClip;
    public class MaClasse extends MovieClip
    {
        public function MaClasse() 
        {
        }
    }
}

Création du clip dans Flash et attachement de la class MaClasse

Créer pour cela un clip dans la bibliothèque Flash, cliquez droit sur le clip et affichez les propriétés, cohez la case "Exporter pour actionscript", ce qui vous permettra de lier ce clip à une classe Actionscript.

Création de classe en Javascript

Remplissez les champs comme indiqué sur l'illustration : la classe est donc MaClasse, et la classe de base MovieClip, puis cliquez sur OK.

Vous pouvez désormais manipuler votre classe comme vous le souhaitez.

Héritage

Vous pouvez ajouter des attributs et vous avez accès à tous les attributs de base de la classe MovieClip (x, y, alpha ...) puisque MaClasse hérite totalement de la class MovieClip.

Instanciation

Comme les autres classes, avec le mot clé new, vous pouvez même typer les variables pour avoir la complétion dans FlashDevelop :

var oMaClasse:MaClasse = new MaClasse();

Cette classe pourra avoir d'autres classes personnalisées comme attribut.

Création dynamique d'attribut

On peut si l'on souhaite attribuer dynamiquement des attributs à notre classe (prototype), il faut pour cela employer le mot clé dynamic lors de la déclarion de la classe :

dynamic public class MaClasse extends MovieClip
{
//...
}

Conclusion

Actionscript 3 (AS3) permet aux développeurs peu familiers de Flash de rapidement s'y mettre : c'est de la programmation orientée objet classique. De plus, FlashDevelop offre un environnement de développement simple et intuitif.

Articles connexes

Notez cet article !

  • Actuellement 4.5 sur 5 étoiles
  • 1
  • 2
  • 3
  • 4
  • 5

Note : 4.7/5 (3 notes attribuées)

Merci d'avoir participé !

Vous avez déjà noté cette page, vous ne pouvez la noter qu'une fois !

Votre note a été changée, merci de votre participation !

Bonne résolution ! j'arrête d'alourdir mes pages avec des boutons de partage, mais vous pouvez continuer de partager :-)

Commentaires

  1. You have a very inspiring way of exploring and sharing your thoughts. N doubt, info is original and very well structured. Keep it up.

  2. cannabis... | cannabis online ordering software |

    A very interesting read. I would like to thank you for the efforts you had made for writing this awesome article.

  3. Candidates looking for the Junior School Certificate (JSC) exam results can find the complete details here. The board is likely to declare the JSC Result 2018 soon in their official website. Check the exact publish date of the results and the time from here.
    https:/...sc-result/

  4. Your work is very good and I appreciate you and hopping for some more informative posts. Thank you for sharing great information to us.
    http://...important/

  5. Interesting and amazing how your post is! It Is Useful and helpful for me That I like it very much, and I am looking forward to Hearing from your next.
    http://...-his-body/

  6. I really impressed after read this because of some quality work and informative thoughts . I just wanna say thanks for the writer and wish you all the best for coming!

  7. Thanks for your information, it was really very helpfull.
    http://...sphere.com

  8. Hi, I have scanned the greater part of your posts. This post is presumably where I got the most valuable data for my exploration. A debt of gratitude is in order for posting, possibly we can see more on this. Are you mindful of some other sites on this subject.
    http://...education/

  9. That is the excellent mindset, nonetheless is just not help to make every sence whatsoever preaching about that mather. Virtually any method many thanks in addition to i had endeavor to promote your own article in to delicius nevertheless it is apparently a dilemma using your information sites can you please recheck the idea. thanks once more.
    http://...-business/

  10. mohit4son... | mohit |

    This is so fun! What a great idea. Also I love how authentic you seem to be. Your style and passion for blogging is contagious. Thank you for sharing your life!
    https:/...nd-quotes/

  11. canola oil, egg product, bison, roasted venison, beef, all-natural taste, tomato pomace, potato healthy protein.

  12. Positive site. where did u come up with the information on this posting?I have read a few of the articles on your website now. and I really like your style. Thanks a million and please keep up the effective workhttp://...launch.com

  13. team buil... | team building escape room |

    A very interesting read. I would like to thank you for the efforts you had made for writing this awesome article.<a href="https:/...t;>team building escape room</a>

  14. lionelabi... | obat sesak nafas karena jantung |

    This article is very useful, thank you for sharing. And allow me to share articles too, it's about health and treatment. God willing it will be useful for us all. Thank you
    https:/...ntung.html

  15. lionelabi... | obat sesak nafas karena jantung |

    This article is very useful, thank you for sharing. And allow me to share articles too, it's about health and treatment. God willing it will be useful for us all. Thank you

  16. ciduksumu... | Agen Judi Online Terpercaya |

    Situs Terbaik dan Terpercaya
    <a href="http://...biz/" rel="nofollow">Poker Online Terbaik</a>
    <a href="http://...biz/" rel="nofollow">Bandar Togel Terpercaya</a>
    <a href="http://...com/" rel="nofollow">Agen Poker Online</a>
    <a href="http://...com/" rel="nofollow">Prediksi Togel</a>
    <a href="http://...ine/" rel="nofollow">Video Bokep</a>
    <a href="http://...nfo/" rel="nofollow">Info Poker Online</a>
    <a href="http://...nfo/" rel="nofollow">Info Judi Poker</a>
    <a href="http://...nfo/" rel="nofollow">Info Bandar Togel</a>
    <a href="http://...nfo/" rel="nofollow">Info Taruhan Bola</a>
    <a href="http://...com/" rel="nofollow">Bandar Judi Online</a>
    <a href="http://...com/" rel="nofollow">Agen Togel Online</a>
    <a href="http://...com/" rel="nofollow">Agen Poker Indonesia</a>
    <a href="http://...org/" rel="nofollow">Judi Bola Online</a>
    <a href="http://...com/" rel="nofollow">Poker Online Terpercaya</a>
    <a href="http://...com/" rel="nofollow">Judi Poker Terbaik</a>
    <a href="http://...ite/" rel="nofollow">Situs Togel</a>
    <a href="http://...com/" rel="nofollow">Togel Online Aman</a>
    <a href="http://...org/" rel="nofollow">Poker Online Uang Asli</a>
    <a href="http://...com/" rel="nofollow">Situs Poker</a>

  17. Webroot.com/safe- Experience next-generation Security level with Webroot on your all devices. Install and activate webroot from www.webroot.com/safe and don’t forget to run webroot safe scan to feel secure anywhere.webroot.com/safe is a computer security software program for Microsoft Windows users that combine software as a service cloud protection with traditional Antivirus and anti-spyware desktop technologies. Built into the suite is a two-way firewall, a registry cleaner, Email anti-spam, secure browsing, anti-phishing and a password management service. The suite was initially released on July 26, 2010, as the 2011 version of the product.

    http://...t.com/safe

  18. A very interesting read. I would like to thank you for the efforts you had made for writing this awesome article.

  19. www.webroot.com/safe -24/7 technical support for Webroot antivirus, call us to get instant support on webroot installation issues Dial toll free 1-844-833-0610.
    https:/....org/safe/

  20. Where to seek out webroot Key Code? The Webroot security package is simple to setup &amp; install at webroot.com/safe. Simply find 20-character alpha-numeric code that is...
    http://...-safe.org/

  21. Web-root -24/7 technical support for Webroot antivirus, call us to get instant support on webroot installation issues Dial toll free 1-844-833-0610.
    https:/...-root.org/

  22. Experience next generation Security level with Webroot in your all devices. Install and activate webroot from www.webroot.com/safe and don’t forget to run webroot safe scan to feel secure anywhere.
    https:/...-com-safe/

  23. www.webroot.com/safe -24/7 technical support for Webroot antivirus, call us to get instant support on webroot installation issues Dial toll free 1-844-833-0610.
    https:/....org/safe/

  24. Where to seek out webroot Key Code? The Webroot security package is simple to setup &amp; install at webroot.com/safe. Simply find 20-character alpha-numeric code that is...
    http://...-safe.org/

  25. Web-root -24/7 technical support for Webroot antivirus, call us to get instant support on webroot installation issues Dial toll free 1-844-833-0610.
    https:/...-root.org/

  26. Experience next generation Security level with Webroot in your all devices. Install and activate webroot from www.webroot.com/safe and don’t forget to run webroot safe scan to feel secure anywhere.
    https:/...-com-safe/

  27. www.webro... | www.webroot.com/safe | webroot/safe - download (windows 10) |

    Webroot Support provides all-round assistance for Webroot Antivirus. As soon as you register yourself for the use of Internet facility and get the advantage of surfing the World Wide Web, you are open to innumerable threats transmitted to your system due to online browsing sessions. Encounter perfect malware blocking with Webroot Antivirus. Let Webroot Support with its techsmarties help you protect your system and rectify the security issues. We at Webroot Support , have team of experts who help you or guide through all the stages of Webroot installation process.
    http://....org/safe/

  28. www.webro... | www.webroot.com/safe | Activate webroot at webroot safe |

    Where to seek out webroot Key Code? The Webroot security package is simple to setup &amp; install at webroot.com/safe. Simply find 20-character alpha-numeric code that is...
    http://...-safe.org/

  29. Web-root -24/7 technical support for Webroot antivirus, call us to get instant support on webroot installation issues Dial toll free 1-844-833-0610.
    http://...b-root.org

  30. webroot.c... | webroot.com/safe to get webroot safe setup |

    Webroot Support experts can lend their hand to download, install and update Webroot Spy Sweeper Antivirus on your system. We can also repair all errors that may crop up while installing and configuring Webroot Antivirus on your PC. We can help you detect and remove malicious threats, malware and spyware by performing a quick scan on all files and folders. With our robust technology, we can destroy suspicious programs and infected files from your system. Our antivirus experts can clean all online threats, including Trojan, root kits, key loggers, and worms in just single sweep. We can optimize your computer’s speed and efficiency and also protect it from being sluggish.
    http://...-com-safe/

  31. Visit www.norton.com/setup for setup, download, reinstall, enter and activate your norton product key to setup your account.Step-by-Step guide for Norton setup key, Download &amp; installation from norton.com/setup website.

  32. welcome to avg.com/retail website With the development of the digital world, online protection is crucial. It is extremely important to protect your PCs, Mac, computers as well as mobile devices and tablets with avg.com/retail. This can be done with the help of effective internet security and anti-virus products from avg.com/retail that safeguards all devices used on digital platforms.

  33. Thank you for sharing the information! The idea of changing battery sounds better than waiting for the battery to recharging.

  34. 3d render... | 3d rendering services in vietnam |

    In this particular article, you will see a summary, satisfy browse this post.

  35. Wal-mart is one of the places where we can find all our needs of life under one roof and it is the one-stop service provider for all family requirements. This is been in operation for 50 years. It has a wide network of more than 260 million customers where they visit 12000 stores. Also, don’t surprised there are 2.3 million employees to service our needs. Myfamilymobile is a part of Global giant Wal-mart. Wal-mart sells famous mobile brands in its stores.

  36. Business... | Business Setup in Dubai |

    Hi buddy, your blog' s design is simple and clean and i like it. Your blog posts about Online writing Help are superb. Please keep them coming. Greets!

  37. Buy Psych... | Buy Psychology Assignment Help |

    I loved the way you discuss the topic great work thanks for the share.

  38. Lots of people worry in buying applications & video games in Play Store. Do not fret good friends Appvn application latest variation is Free absolutely with no money acquisition.

  39. I am continually hunting on the web down articles that can help me. There is clearly a considerable measure to think about this. I think you made some great focuses in Features too. Continue working, extraordinary job !

  40. I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

  41. http://ww... | http://www.agenslutena.com/penyebab-retina-lepas-ablasio-retina-obat-ampuh-tanpa-operasi/ |
  42. nice article

  43. nettoyer... | nettoyer son electromenager |

    Totally awesome posting! Loads of valuable data and motivation, both of which we all need!Relay welcome your work.

  44. You're so awesome! I don't believe I've read through a single thing like this before. So great to discover someone with a few original thoughts on this subject. Seriously.. thank you for starting this up. This web site is one thing that is required on the internet, someone with some originality! <a href="http://...ot;>Gta cheats online</a>

  45. You're so interesting! I don't think I've truly read through something like that before. So great to discover someone with a few genuine thoughts on this subject. Seriously.. thanks for starting this up. This web site is one thing that's needed on the internet, someone with a little originality! <a href="http://...ot;>gta 5 cheats online</a>

  46. Angry Bir... | Angry Birds Match Free Gems |

    Wonderful blog post. This is absolute magic from you! I have never seen a more wonderful post than this one. You've really made my day today with this. I hope you keep this up!
    Angry Birds Match Free Gems

  47. There are a number of plays of food show. This show is the greater podcast that can be watched at YouTube also. You would also like to listen about the Company where I do job which provides best creative writer India which can make your show more popular.

  48. This was nice and impressive post i read it and it was incredible thank you so much for sharing this kind of info with us you are so good and amazing with your work i appreciate that thank you.

  49. Great info! I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have 

  50. Regular visits listed here are the easiest method to appreciate your energy, which is why why I am going to the website everyday, searching for new, interesting info. Many, thank you  <a href="http://...>Boston Terrier Friend</a>

  51. Superb examining .Thanks for sharing. It's late finding this show up.

  52. one thing that i like about the blog could be that the information is very helpful and keeps one informed on issues related to politics. 

  53. It is the best portal to pay bills online within minutes without any complications. It avails maximum possible flexibility to users to complete their tasks in real quick time. Apart from bill payments it also avails most popular and reputed brands products to customers in affordable prices. PayTM came into existence in 2010.

  54. windowcle... | windowcleanersaustin.com |

    Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.

  55. comment p... | comment pirater un compte snapchat |

    Thanks for sharing this information. I really like your blog post very much. You have really shared a informative and interesting blog post with people..

  56. If you don"t mind proceed with this extraordinary work and I anticipate a greater amount of your magnificent blog entries. 

  57. Wow, this is really interesting reading. I am glad I found this and got to read it. Great job on this content. I like it.

  58. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.

  59. I'm constantly searching on the internet for posts that will help me. Too much is clearly to learn about this. I believe you created good quality items in Functions also. Keep working, congrats!

  60. Just pure brilliance from you here. I have never expected something less than this from you and you have not disappointed me at all. I suppose you will keep the quality work going on.

  61. My friend recommended this blog and he was totally right keep up the good work

  62. Visit our site to find more about wedding photographer Northern Virginia. We offer engagement and proposal photography in Va.

  63. Today's Cogniflex review is intended for people looking to buy brain supplements to increase focus and memory.

  64. Pay Someo... | Pay Someone To Take My Online Exam |

    I personally like your post, you have shared good article. It will help me in great deal.

  65. Solidwork... | Solidworks Experts online |

    They are not able to finish the writing assignments on time. For some students, writing any writing assignments is able to waste their time

  66. Lucky Patcher For iOS is one of the best Patcher application for iDevices. You can Download Lucky Patcher For iOS through the custom app ...Lucky Patcher iOS v6.5.2 APK. Do you want to download apk lucky patcher uptodown for free.

  67. I want to say about this article, uummm this is amazing and nice post.

  68. Value-Add... | Value-Added Theory Sociology Help |

    good essay thank you so much i will find you again. hope to read smth like this next time.

  69. Mobdro for PC is a trending online video streaming application. You can free download Mobdro for Laptop/PC on Windows 10/8.1/8/7/xp/vista, Mac.

  70. Your write-ups are far more than wow!

  71. blog comm... | blog comments services |

    You have a genuine capacity for composing extraordinary substance. I like how you think and the way you speak to your perspectives in this article. I concur with your state of mind. Much obliged to you for sharing.

  72. This article is such a nice and interesting one, I'm very satisfied with the provided contents. I hope more excellent articles would be posted in your website. Thank you so much for this and keep sharing.

  73. J'ai fait une nuit blanche pour je trouve la methode d'appeler class depuit clip, maintenant votre article regle mon probleme.
    Merci beaucoup