www.mutationevent.com

Articles taggés avec ‘as3’

as3 TypeWriter Effect

Lundi 10 août 2009

code source :

  1. import com.mutationevent.TypeWriter;
  2. var tw:TypeWriter = new TypeWriter(theText, 1, 10);
  3. tw.addEventListener(TypeWriter.COMPLETE, onComplete);
  4. function onComplete(event:Event)
  5. {
  6. trace("complete", event);
  7. }

class :

  1. /*
  2. * Copyright 2009 Achraf bouyakhsass [http://www.mutationevent.com]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.mutationevent
  17. {
  18. import flash.events.*;
  19. import flash.utils.Timer;
  20. import flash.text.TextField;
  21.  
  22. public class TypeWriter extends EventDispatcher
  23. {
  24. private var timer:Timer;
  25. private var count:Number = 0;
  26. private var str:String;
  27. private var target:TextField;
  28. private var charJump:Number = 1;
  29. private var speed:Number = 50;
  30. public static var COMPLETE:String = "complete";
  31.  
  32. public function TypeWriter(tf:TextField, cj:Number, sp:Number)
  33. {
  34. charJump = cj;
  35. speed = sp;
  36. target = tf;
  37. str = target.text;
  38. target.text = "";
  39.  
  40. timer = new Timer(speed);
  41. timer.addEventListener(TimerEvent.TIMER, write);
  42. timer.start();
  43. }
  44. private function write(event:TimerEvent):void
  45. {
  46. target.text = str.substring(0, count);
  47. count += charJump;
  48. if(count > str.length)
  49. {
  50. timer.removeEventListener(TimerEvent.TIMER, write);
  51. dispatchEvent(new Event(TypeWriter.COMPLETE));
  52. }
  53. }
  54. }
  55. }

Télécharger le fichier ici : as3 TypeWriter (88)

as3 CountDown

Samedi 8 août 2009

Réaliser un compte a rebours facilement avec as3.

Nous aurons besoin un champ de texte pour afficher la date, un timer et la classe CountDown de Kazuma Ieiri.

code as 3

import flash.utils.Timer;
import flash.events.TimerEvent;
import jp.hbkr.baka.CountDown;
 
var timer:Timer = new Timer(1000);
var a:Array;
 
timer.addEventListener(TimerEvent.TIMER, tick);
timer.start();
 
function tick(event:TimerEvent):void
{
a = CountDown.getCountDown(2010, 1, 1, 12, 0, 0);
timerContentTXT.text = a[0]+" Jours "+a[1]+" H " + a[2] + " mn et " + a[3]+"s";
}

Télécharger la source ici CountDown (119)

Les bibilithèques d’annimations (Tween Library) en AS3

Samedi 30 mai 2009

default file type in Air Application

Vendredi 9 janvier 2009

Imaginez que vous êtes en train de développer une application pour lire des fichiers au format .flv, .txt ou votre propre format et vous voudriez qu'à chaque fois que l'utilisateur double clique sur le fichier votre application créée avec Adobe Air se lance automatiquement. vous n'aurez qu'a utiliser se code

NativeApplication.nativeApplication.setAsDefaultApplication("flv");

pour faire mieux encore, vous pouvez vérifier si votre application est l'application par défaut de ce type

NativeApplication.nativeApplication.isSetAsDefaultApplication("flv");

si ce n'est pas le cas, vérifier l'application par défaut de ce type de fichier

NativeApplication.nativeApplication.getDefaultApplication("flv");

cela renvoi le chemin vers l'application lier a ce format de fichier. Et pour faire en sorte que votre application ne soit plus lier a ce format de fichier :

NativeApplication.nativeApplication.removeAsDefaultApplication("flv");

Télécharger un fichier avec AS 3

Samedi 20 décembre 2008

Nous savons que pour télécharger un fichier depuis un site avec la machine du client il suffit parfois de le compresser en .zip par exemple et l'ouvrir comme n'importe quel lien et c'est le navigteur qui ouvre la fenêtre de téléchargement puisqu'il n'arrive pas reconnaître ou interpréter le fichier. Mais parfois on a besoin de forcer le téléchargement de certains fichiers cela est possible avec les langages des programmations côté serveur tel que PHP, ASP, JSP, RoR, CFM ...

Cela est désormais possible avec ActionSscript 3, pour cela on besoin de la class FileReference qui se trouve dans le package flash.net.FileReference et qui permet de télécharger n'importe quel fichier grâce à la méthode download.

Supposons que nous voulons télécharger un fichier .zip depuis une URL (http://www.votreserveur.com/fichier.zip)

on peut aussi ajouter des écouteurs d'événement pour savoir si le fichier est en cours de téléchargement, s'il y a eu une erreur, si le téléchargement est terminé et même aussi d'arrêter le téléchargement.

Event.CANCEL
Event.COMPLETE
Event.OPEN
Event.SELECT
HTTPStatusEvent.HTTP_STATUS
IOErrorEvent.IO_ERROR
ProgressEvent.PROGRESS
SecurityErrorEvent.SECURITY_ERROR
DataEvent.UPLOAD_COMPLETE_DATA

code:

package
{
    import flash.display.MovieClip;
    import flash.net.FileReference;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.events.IOErrorEvent;
 
    public class Main extends MovieClip
    {
 
        // Constants:
        // Public Properties:
        public var fileDownload:FileReference;
        public var url:URLRequest;
 
        // Private Properties:
 
        // Initialization:
        public function Main() {
 
            trace("main class loaded");
 
            fileDownload = new FileReference();
            url = new URLRequest("http://www.votreserveur.com/fichier.zip");
 
            fileDownload.addEventListener(ProgressEvent.PROGRESS, onProgress);
            fileDownload.addEventListener(Event.COMPLETE, onComplete);
            fileDownload.addEventListener(IOErrorEvent.IO_ERROR, onError);
 
            fileDownload.download(url);
 
        }
 
        // Public Methods:
        public function onProgress(event:ProgressEvent):void
        {
            trace("chargement en cours : " + event.bytesLoaded / event.bytesTotal);
        }
 
        public function onComplete(event:Event):void
        {
            trace("téléchargement terminer");
        }
 
        public function onError(event:IOErrorEvent):void
        {
            trace("Erreur de chargement du fichier");
        }
 
        // Protected Methods:
    }
 
}

Télécharger le fichier Download File as3 (479)

  • Archives

  • Catégories

  • @mutationevent