Re: [問題] FLEX中 mxml與as

看板Flash作者時間14年前 (2009/10/30 20:33), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串4/4 (看更多)
經過C大的指點 我把程式做了修改,黃色是我做了修改的部份 ※ 引述《forgot75421 (伏加特I》之銘言: 先說聲抱歉 我的中文實在是太差 講不出我所想表達的 所以我把我的程式碼貼上來 下面是mxml檔 <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" fontSize="16" > <mx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; private var localstring:String="../amfphp/services/flex/box.dae"; 當我在裡面填入localstring時是OK的 可以執行 private var obj3d:PV3D = new PV3D(localstring); 可是當我把它改成String(testvalue.text)就不能了 private var obj3d:PV3D = new PV3D(String(testvalue.text)); 錯誤是 無法存取NULL物件的參考屬性或方法 private function PV3DModel():void{ this.PV3DArea.addChild(this.obj3d); } ]]> </mx:Script> <mx:Button label="Button" click="PV3DModel()"/> <mx:Label id="testvalue" text="../amfphp/services/flex/box.dae"/> <mx:HBox width="100%" height="100%"> <mx:Panel width="100%" height="100%" title="PV3D"> <mx:UIComponent id="PV3DArea" width="100%" height="100%"/> </mx:Panel> </mx:HBox> </mx:Application> 下面是as檔 package { import flash.display.Sprite; import flash.events.Event; import org.papervision3d.objects.parsers.DAE; import org.papervision3d.view.BasicView; public class PV3D extends Sprite { private var view:BasicView; private var dae:DAE; public var _localstring:String; public function PV3D(st:String) { this._localstring=st; init3D(); PV3DObject(); } private function init3D():void{ view = new BasicView(0,0,true,true,"Target") this.addChild(view); this.addEventListener(Event.ENTER_FRAME, onEventRender3D) } private function onEventRender3D(e:Event):void{ dae.rotationY -= 5; view.singleRender(); } private function PV3DObject():void{ dae = new DAE(); dae.load(this._localstring); dae.scale=5; view.scene.addChild(dae); } } } 我在想會不會是一開始load時它會先去跑Script然後才跑後面的程式?? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.45.146.108

10/31 00:10, , 1F
你應該要在oncreationcomplete的時候才能讀到Label的值吧?
10/31 00:10, 1F

10/31 00:10, , 2F
更正,creationComplete
10/31 00:10, 2F

10/31 00:27, , 3F
所以說我這樣寫是行不通的囉?
10/31 00:27, 3F
文章代碼(AID): #1Awjqq-0 (Flash)
文章代碼(AID): #1Awjqq-0 (Flash)