mardi 5 juillet 2011

Lien html dans flash (as3)

  1. import flash.text.TextField;  
  2. import flash.events.TextEvent;  
  3.   
  4. var zoneText:TextField = new TextField;  
  5. zoneText.htmlText = "<a href="event:client">Jack</a>   <a href="event:directeur">Leonardo</a>";  
  6. zoneText.addEventListener(TextEvent.LINK,lienClique);  
  7. addChild(zoneText);  
  8. function lienClique(e:TextEvent):void{  
  9.  switch(e.text){  
  10.   case "client":  
  11.    trace("vous avez choisi jack");  
  12.   break;  
  13.   case "directeur":  
  14.    trace("vous avez choisi Leonardo");  
  15.   break;  
  16.   }  
  17.  } 

(as3) charger un fichier CSS dans flash

  1. /*******/ Fichier "style.css" /********** 
  2. h1{ 
  3.  font-size:24; 
  4.  color:#FF0000; 
  5.  font-family:Comic Sans MS; 
  6.  font-weight:bold; 
  7. } 
  8.  
  9. a { 
  10.  font-size:12; 
  11.  color:#2428db; 
  12.  font-family:Verdana; 
  13.  text-decoration:underline; 
  14. } 
  15. a:hover { 
  16.  text-decoration:none; 
  17.  font-weight:bold; 
  18. } 
  19. /*******/ Fichier "style.css" /**********  
  20.   
  21. import flash.display.Loader;  
  22. import flash.text.TextField;  
  23. import flash.text.StyleSheet;  
  24. import flash.net.URLLoader;  
  25. import flash.net.URLRequest;  
  26. import flash.events.TextEvent;  
  27. import flash.events.Event;  
  28. import flash.events.IOErrorEvent;  
  29.   
  30. var fichierCss:StyleSheet = new StyleSheet();  
  31. var chargerCss:URLLoader = new URLLoader();  
  32. var zoneText:TextField = new TextField;  
  33.   
  34. chargerCss.load(new URLRequest("style.css"));  
  35. chargerCss.addEventListener(Event.COMPLETE,parseCss);  
  36.   
  37.   
  38. function parseCss(e:Event):void{  
  39.  fichierCss.parseCSS(e.target.data);  
  40.  zoneText.styleSheet = fichierCss;  
  41.  zoneText.width = 400;  
  42.  zoneText.height = 100;  
  43.  zoneText.addEventListener(TextEvent.LINK,lienClique);  
  44.    
  45.  zoneText.htmlText = "<h1>Mon Titre</h1><img id="test_img" src="img.png"> <a href="event:lirePlus">Lire plus</a>   <a href="#">Lien Normal</a>";  
  46.  addChild(zoneText);  
  47.  // pour charge une image apartire de la tag <img> de HTML  
  48.  var chragerImg:Loader = zoneText.getImageReference("test_img") as Loader;  
  49.  chragerImg.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,noImage);  
  50.  chragerImg.x = 160;  
  51.  addChild(chragerImg);  
  52. }  
  53. function noImage(erreur:IOErrorEvent):void{  
  54.  trace("l'image (img.png) n'existe pas");  
  55.  }  
  56. function lienClique(e:TextEvent){  
  57.  trace(e.text);  
  58.  }