J'ai un soucis que je n'arrive pas à élucider. Je fais quelques manipulations sur des composants, et il arrive que des erreurs remontent. Avec des try - Catch, je devrai pouvoir contourner ce problème, mais seulement voilà, ça ne marche pas.
Voici un exemple, mon code est bien plus compliqué :
CODE
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:TabNavigator id="myTabNav" width="100%">
<mx:Panel id="pan1" label="Panel 1" />
<mx:Panel id="pan2" label="Panel 2"/>
<mx:Panel id="pan3" label="Panel 3"/>
</mx:TabNavigator>
<mx:Button label="Supprimer panel 2" click="deletePanel2()" />
<mx:Script>
<![CDATA[
private function deletePanel2 () : void
{
try {
myTabNav.removeChild(pan2);
}
catch ( e : ArgumentError ) {
trace ("L'erreur est catchée");
}
}
]]>
</mx:Script>
</mx:Application>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:TabNavigator id="myTabNav" width="100%">
<mx:Panel id="pan1" label="Panel 1" />
<mx:Panel id="pan2" label="Panel 2"/>
<mx:Panel id="pan3" label="Panel 3"/>
</mx:TabNavigator>
<mx:Button label="Supprimer panel 2" click="deletePanel2()" />
<mx:Script>
<![CDATA[
private function deletePanel2 () : void
{
try {
myTabNav.removeChild(pan2);
}
catch ( e : ArgumentError ) {
trace ("L'erreur est catchée");
}
}
]]>
</mx:Script>
</mx:Application>
Dans cet exemple, il me suffirait de faire un test d'existance, mais dans mon projet, cela m'est impossible. ce que je ne comprend pas, c'est que je suis censé attraper l'erreur avant qu'elle ne survienne :/