Question

Si je suis le chargement des images via la balise dans un champ de texte dynamique et un IOError est jeté, qu'aurais-je attacher l'écouteur d'événement aussi? le champ de texte? J'ai essayé ...

var textField:TextField = new TextField();
textField.htmlText = "here is some text <img src='image.jpg'> and then some more";
textField.addEventListener(IOErrorEvent.IOError, function (e:Event):void { trace("error caught") });

en vain ...

Suggestions?

Était-ce utile?

La solution

Vous devez définir un id à img puis l'utiliser dans getImageReference sur votre TextField pour obtenir le Loader où vous pouvez ajouter tous les événement que vous voulez:

import flash.display.Loader;
import flash.events.IOErrorEvent;
import flash.text.TextField;

//...
var tfd:TextField = new TextField();
tfd.htmlText = 
      "here is some text <img id='myImg' src='image.jpg' /> and then some more";
var ldr:Loader = tfd.getImageReference("myImg") as Loader;
if (ldr != null) {
 ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
}
//...
private function onIOError(e:IOErrorEvent):void{
 //...
}

Un autre exemple si vous voulez

Autres conseils

J'ai solution pour toi:

tField.addEventListener( Event.ADDED, addedObjectToFieldHandler, true );

function addedObjectToFieldHandler( event:Event ):void
{
   if ( event.target is Loader )
   {
       ( event.target as Loader ).contentLoaderInfo.addEventListener( IOErrorEvent.IO_ERROR, function( e:IOErrorEvent ):void{} );
   }
}

qui empêchera flashplayer de lancer des erreurs et chaque fois que l'accident lien image est cassé

vous devez utiliser un bloc catch try:

try
{
  var textField:TextField = new TextField();
  textField.htmlText = "here is some text <img src='image.jpg'> and then some more";
}
catch( error:IOError )
{
    //handle IOError
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top