Hello All,

I have a TitleWindow component with the "lightbox" or Alert "effect"
(background blurred) 
from which I insert some news, here is the code :
/////////////////////////////////////////////////////////////////////
import model.NewsManager;
import mx.managers.PopUpManager;
        
        private var nm:NewsManager = new NewsManager();
        
        private function init():void
        {
                nm.addEventListener( "NEWS_SENT", refreshNewsHandler ); 
        }
        
        public function submitNews():void
        {
                var newsSubmitArray:Array = new Array();
                // Don't post empty user records to the database
                if ( in_titre_news.text=='' || in_txt_news.text=='' )
                {
                        // implémenter logique des champs vides 
                        return;
                }       
                newsSubmitArray.in_titre_news = in_titre_news.text;
                newsSubmitArray.in_txt_news = in_txt_news.text;
                newsSubmitArray.in_aut_news = in_aut_news.text;
                newsSubmitArray.in_src_img = in_src_img.text;
                
                nm.createNewsObj( newsSubmitArray );
                
                in_titre_news.text = '';
                in_txt_news.text = '';
                in_aut_news.text = '';
                in_src_img.text = '';
                // indique que la news est créée
                lbl_alert.visible = true;
        }
        private function refreshNewsHandler( evt:Event ):void
        {
                nm.getNewsObj();
                 if ( evt.type == "NEWS_SENT" ) 
                this.parentApplication.updateAffichageNews(); 
        }
/////////////////////////////////////////////////////////////////////   
The NewsManager is a class which manages the RemoteObject (I'm using
AmfPhp) :
/////////////////////////////////////////////////////////////////////
[Bindable]
        public class NewsManager extends EventDispatcher
        {
                private var ro:RemoteObject;
                public var getNewsArray:ArrayCollection;
                public var lv:LoginView;
                public var _lbl_nook_VISIBLE:int;
                
                public function NewsManager()
                {
                        ro = new RemoteObject( "amfphp" );
                        ro.source = "NewsService";
                }
                
                public function createNewsObj( a:Array ):void
                {
                        ro.getOperation( "createNews" ).addEventListener(
ResultEvent.RESULT, createNewsResultHandler );
                        ro.getOperation( "createNews" ).addEventListener( 
FaultEvent.FAULT,
faultHandler );
                        ro.getOperation( "createNews" ).send( a );
                }
                
                private function createNewsResultHandler( evt:ResultEvent ):void
                {
                        dispatchEvent( new Event( "NEWS_SENT" ) );
                }

                public function getNewsObj():void
                {
                        ro.getOperation( "getNews" ).addEventListener( 
ResultEvent.RESULT,
getNewsResultHandler );
                        ro.getOperation( "getNews" ).addEventListener( 
FaultEvent.FAULT,
faultHandler );
                        ro.getOperation( "getNews" ).send();
                }
                
                private function getNewsResultHandler( evt:ResultEvent ):void
                {
                        var obj:Object = evt.result as Object;
                        getNewsArray = new ArrayCollection();
                                var i:int = 0;
                        for each ( var item:Object in obj )
                        {
                                getNewsArray.addItem( item );
                                i++;
                        }       
                }
                
                public function manageUserObj( u:String, p:String ):void
                {
                        ro.getOperation( "manageUser" ).addEventListener(
ResultEvent.RESULT, manageUserResultHandler );
                        ro.getOperation( "manageUser" ).addEventListener( 
FaultEvent.FAULT,
faultHandler );
                        ro.getOperation( "manageUser" ).send( u, p );
                }
                
                private function manageUserResultHandler( evt:ResultEvent ) : 
void
                {
                        if ( evt.result == 0 )
                        {
                                dispatchEvent( new Event("VISIBLE_EVENT") );
                        }
                        else if ( evt.result == 1 )
                                {
                                        dispatchEvent( new 
Event("INVISIBLE_EVENT") );
                                }
                }
                
                private function faultHandler( evt:FaultEvent ):void
                {
                        Alert.show( evt.fault.faultString, 
evt.fault.faultCode.toString() );
                }
/////////////////////////////////////////////////////////////////////
And in the main the updateAffichageNews() function :
/////////////////////////////////////////////////////////////////////
public function updateAffichageNews(  ):void
{
        nm.getNewsObj();
        vb_news.removeAllChildren();
        afficheNews();
}
public function afficheNews():void
{
        for ( var i:int=0; i < nm.getNewsArray.length; i++ )
        {
                news = new NewsView();
                vb_news.addChild( news );
                news.lbl_titre_news.text = nm.getNewsArray[i].titre_news;
                news.txta_news.text = nm.getNewsArray[i].txt_news;
                news.lbl_aut_news.text = nm.getNewsArray[i].aut_news;
                if ( nm.getNewsArray[i].src_img != null )
                {
                        news.img_news.source = nm.getNewsArray[i].src_img;
                }
                        else
                        {
                                news.img_news.visible = false;
                        }
        }
}
/////////////////////////////////////////////////////////////////////
The thing is that I'd like to "refresh" the whole news (Canvas + VBox)
which are behind the TitleWindow just after I created the news and so
cliked on the submit button...
But things go too fast and the  updateAffichageNews() function is
called before all the datas are returned with the new news just created.
I put a dispatchEvent to prevent this but it's not really effective.
Somebody would have a suggestion ?

Thx !
        

Reply via email to