Flash/PHP/Mysql - Partie 5: Mettons ça au propre !
Submitted by PiTiLeZarD on Mon, 04/02/2007 - 19:26
Tagged:
Voila ce billet n'ajoute aucune information par rapport aux précédents, simplement j'ai mis de l'ordre et j'ai rendu tout ça fonctionnel alors je montre :
Dans un premier temps pour m'éviter de toujours naviguer entre la fenêtre Action et les autres, j'ai tout simplement fait une classe Main et je l'appelle comme ça dans ma fenêtre Action :
import Main; var main:Main = new Main();
Voila ... après je fais tout de là c'est plus simple à gérer ! Bon et je fais quoi de là ? en fait voilà l'enchainement :
- Je construit le CSS et je l'associe au bon endroit
- Une fois tout ça fait je fais un loader et je load les news
- Une fois les news loadé, je traite les données et je les ajoutes au textField
Simplissime :
import JSON; import StringHelper; import News; class Main { public var baseUrl = "http://localhost:8888/projetFlash/"; public var urlNewsList:String = "News/jsonList"; public var urlNewsPost:String = "News/addNew"; public var urlCssFlash:String = "Css/flash"; private var cssStyle:Object = null; private var news:String = null; // dummy value due to mix between ActionScript1 and ActionScript2 public function Main() { trace("Building Main Class"); this.cssStyle = new TextField.StyleSheet(); this.cssStyle.onLoad = this.onCssLoaded; this.cssStyle.load(this.baseUrl + this.urlCssFlash); } public function onCssLoaded(ok:Boolean):Void { if (ok) { var tf:Object = _root.newsTextField; tf.html = true; tf.multiline = true; tf.htmlText = ''; tf.styleSheet = this; // We are inside the StyleSheet object _root.main.loadNews(); } } public function loadNews():Void { var loader:LoadVars = new LoadVars(); loader.onLoad = this.onNewsLoaded; loader.load(this.baseUrl + this.urlNewsList); } public function onNewsLoaded(ok:Boolean):Void { if (ok && this.news) { // this refers to the LoadVars object var tf:Object = _root.newsTextField; var array = JSON.parse(this.news); for (var i = 0; i < array.length; i++) { var news:Object = array[i]; tf.htmlText += '<h2>'+news.tmstp+'</h2>'; tf.htmlText += '<p>'+news.news+'</p>'; } } } }
