Progression Forum
9月 03, 2010, 02:43:03 午前 *
ようこそゲストさん。まずは、ログインするか、ユーザ登録してください。
アクティべーションメール送られて来ませんでしたか?

ユーザ名、パスワード、クッキー保持期間を入力してログインして下さい。
お知らせ:
 
   ホーム   ヘルプ 検索 ログイン 登録  
ページ: [1]
  印刷  
投稿者 スレッド: NextButton(initObject:Object = null)のinitObjectの働き  (参照数 4506 回)
oshige
初心者
*
投稿: 49



プロフィールを見る
« 投稿日:: 10月 23, 2009, 09:06:32 午後 »

NextButtonのインスタンスを作る際に次のように作ってもmanagerIdやuseTurnBackなどのプロパティが設定されないようです。

コード:
 new NextButton( {managerId:"index",useTurnBack:true} )

実際にはNextButtonクラスを継承したNextSceneButtonクラスのsuper(initObject)で初期化しています。

コード:
public class NextSceneButton extends NextButton {
public function NextSceneButton( initObject:Object = null ) {
// 親クラスを初期化します。
super(initObject);
//ボタン
var myButton:Button = new Button();
myButton.label = "Next Scene";
addChild(myButton);
}
インスタンスは次のように作ります。
コード:
nextSceneBtn = new NextSceneButton({managerId:"index",useTurnBack:true});

これではプロパティが設定されず、NextSceneButtonクラスを次のようにすればプロパティを設定できます。

コード:
public class NextSceneButton extends NextButton {
public function NextSceneButton( initObject:Object = null ) {
// 親クラスを初期化します。
super( null );
managerId  = initObject.managerId;
useTurnBack = initObject.useTurnBack;
//ボタン
var myButton:Button = new Button();
myButton.label = "Next Scene";
addChild(myButton);
}

ぼくの仕様の理解が間違っているのかもしれませんが、どうなんでしょう?
ちなみに、PreviousButtonクラスでも同じ結果です。
« 最終編集: 10月 24, 2009, 12:22:05 午前 by oshige » IP記録
nium
管理人
住民メンバー
*****
投稿: 277


プロフィールを見る
« 返信する #1 投稿日:: 10月 24, 2009, 03:30:40 午前 »

ご報告ありがとうございます。

以下のコードで実行してみて問題なく動作するようですが、プロパティが設定されないというのは、値を参照しても正しく返ってこないということでしょうか?もしくは、ただしく動作しないということでしょうか?

もし何かエラーが発生しているようであれば、エラーの内容を教えてください。

コード:
public class Index extends CastDocument {

public function Index() {
super( "index", null, new WebConfig() );
}

protected override function atReady():void {
Debugger.addTarget( manager );

var btn:NextButton = new NextButton( { managerId:"index", useTurnBack:true } );
btn.graphics.beginFill( 0x000000 );
btn.graphics.drawRect( 0, 0, 100, 100 );
btn.graphics.endFill();
addChild( btn );

manager.root.addScene( new SceneObject( "aaa" ) );
manager.root.addScene( new SceneObject( "bbb" ) );
manager.root.addScene( new SceneObject( "ccc" ) );

manager.goto( new SceneId( "/index/aaa" ) );
}
}

IP記録
oshige
初心者
*
投稿: 49



プロフィールを見る
« 返信する #2 投稿日:: 10月 24, 2009, 08:09:59 午前 »

回答ありがとうございます。
むむ!そうですか。もう1度、確認してみます。 疑問
(今日は1日中外出なので、夜になるかな)

ちなみに、ソースはディープリンクの質問のサンプルと同じで、これです。
http://oshige.com/flash/as3study/progression/sample/LoadSWF_pages2.zip
« 最終編集: 10月 24, 2009, 08:12:02 午前 by oshige » IP記録
oshige
初心者
*
投稿: 49



プロフィールを見る
« 返信する #3 投稿日:: 10月 25, 2009, 12:52:34 午前 »

あらためて動作を確認してみました。不思議な結果です。
super( initObject )で指定のプロパティは正しくセットされていることが確認できました。
ところが、やはりサブクラスのsuper( initObject )でプロパティを初期化した場合はNextButtonとして機能せず、super( null ); managerId = initObject.managerId; useTurnBack = initObject.useTurnBack;としてサブクラスで改めてプロパティを設定することでNextButtonとして機能します。
なお、NextSceneButtonクラスではボタンイメージをButtonコンポーネントで作っていますが、Spriteで作っても結果は同じでした。

super( initObject )を使った場合。
NextButtonでindexに戻ってしまう。
http://oshige.com/flash/as3study/progression/sample/LoadSWF_pages3NG/bin-release/

コード:
public class NextSceneButton extends NextButton {
  public function NextSceneButton( initObject:Object = null ) {
   // 親クラスを初期化します。
   super( initObject );
   //super( null );
   //managerId  = initObject.managerId;
   //useTurnBack = initObject.useTurnBack;
   trace("-----NextSceneButton-----------");
   trace("initObject.managerId:"+initObject.managerId, "initObject.useTurnBack:"+initObject.useTurnBack);
   //ボタン
   var myButton:Button = new Button();
   myButton.label = "Next Scene";
   addChild(myButton);
 }
      
コード:
出力結果:
  [info] 外部ライブラリ SWFWheel が有効化されました。
  [info] 外部ライブラリ SWFSize が有効化されました。
-----NextSceneButton-----------
initObject.managerId:index initObject.useTurnBack:true
-----UIPanel-----------
nextSceneBtn.managerId:index nextSceneBtn.useTurnBack:true

(...中略)

----------------------------------------------------------------------
 
  [info] 外部ライブラリ SWFAddress が有効化されました。
  [info] 同期対象の HTML データを読み込みました。
  [info] [Progression id="index"] の準備が完了しました。
  [info] シーン移動を開始, 目的地 = /index
  [info]   シーン /index に移動
  [info]   シーン /index でイベント sceneLoad を実行
  [info]   シーン /index でイベント sceneInit を実行
  [info] 移動先を変更, 目的地 = /index/sceneA
  [info]   シーン /index でイベント sceneGoto を実行
  [info]   シーン /index/sceneA に移動
  [info]   シーン /index/sceneA でイベント sceneLoad を実行
0 / 19544 (0%)
19544 / 19544 (100%)
  [info]   シーン /index/sceneA でイベント sceneInit を実行
  [info] シーン移動を完了

path /sceneA
<<ここでボタンクリック>>
  [info] シーン移動を開始, ]目的地 = /index   <------------------------ 次のシーンへ移動せず、indexへ戻ってしまう。
  [info]   シーン /index/sceneA でイベント sceneGoto を実行
  [info]   シーン /index/sceneA でイベント sceneUnload を実行
  [info]   シーン /index に移動
  [info]   シーン /index でイベント sceneInit を実行
  [info] シーン移動を完了

path /


super( null )にしてプロパティを設定し直した場合。
NextButtonで次のシーンへ移動する。
http://oshige.com/flash/as3study/progression/sample/LoadSWF_pages3/bin-release/
ソースコード一式
http://oshige.com/flash/as3study/progression/sample/LoadSWF_pages3.zip
(NextButtonインスタンスはUIPanelクラスで作っています。)

コード:
public class NextSceneButton extends NextButton {
  public function NextSceneButton( initObject:Object = null ) {
   // 親クラスを初期化します。
   //super( initObject );
   super( null );
   managerId  = initObject.managerId;
   useTurnBack = initObject.useTurnBack;
   trace("-----NextSceneButton-----------");
   trace("initObject.managerId:"+initObject.managerId, "initObject.useTurnBack:"+initObject.useTurnBack);
   //ボタン
   var myButton:Button = new Button();
   myButton.label = "Next Scene";
   addChild(myButton);
 }

出力結果:
 
コード:
[info] 外部ライブラリ SWFWheel が有効化されました。
  [info] 外部ライブラリ SWFSize が有効化されました。
-----NextSceneButton-----------
initObject.managerId:index initObject.useTurnBack:true
-----UIPanel-----------
nextSceneBtn.managerId:index nextSceneBtn.useTurnBack:true

(...中略)

----------------------------------------------------------------------
 
  [info] 外部ライブラリ SWFAddress が有効化されました。
  [info] 同期対象の HTML データを読み込みました。
  [info] [Progression id="index"] の準備が完了しました。
  [info] シーン移動を開始, 目的地 = /index
  [info]   シーン /index に移動
  [info]   シーン /index でイベント sceneLoad を実行
  [info]   シーン /index でイベント sceneInit を実行
  [info] シーン移動を完了

  [info] シーン移動を開始, 目的地 = /index/sceneA
  [info]   シーン /index でイベント sceneGoto を実行
  [info]   シーン /index/sceneA に移動
  [info]   シーン /index/sceneA でイベント sceneLoad を実行
0 / 19544 (0%)
19544 / 19544 (100%)
  [info]   シーン /index/sceneA でイベント sceneInit を実行
  [info] シーン移動を完了

path /sceneA
 <<ここでボタンクリック>>
  [info] シーン移動を開始, 目的地 = /index/sceneB  <---------------------- 次のシーンへ移動する。
  [info]   シーン /index/sceneA でイベント sceneGoto を実行
  [info]   シーン /index/sceneA でイベント sceneUnload を実行
  [info]   シーン /index/sceneB に移動
  [info]   シーン /index/sceneB でイベント sceneLoad を実行
0 / 19545 (0%)
19545 / 19545 (100%)
  [info]   シーン /index/sceneB でイベント sceneInit を実行
  [info] シーン移動を完了

path /sceneB

IP記録
nium
管理人
住民メンバー
*****
投稿: 277


プロフィールを見る
« 返信する #4 投稿日:: 10月 25, 2009, 03:10:53 午後 »

細かく検証頂きありがとうございます。
こちらでも問題を確認しました。

原因ですが、initObject が適用されるタイミングと Progression インスタンスの生成タイミング、それらが関連付けられるタイミングに、一瞬だけ隙があったようで、プロパティとしては設定されるが、Progression インスタンスとの関連付けには失敗していたというのが原因のようです。

次のアップデート時に修正させて頂きますね。
IP記録
oshige
初心者
*
投稿: 49



プロフィールを見る
« 返信する #5 投稿日:: 10月 25, 2009, 04:32:35 午後 »

よかったーというか、よくなかったーというか ニヤリ

初期化タイミングをいろいろ変えてテストしている最中でした。
それでは次のバージョンまで待つことにしてテストは打ち切ります。
ありがとうございました。
IP記録
oshige
初心者
*
投稿: 49



プロフィールを見る
« 返信する #6 投稿日:: 10月 28, 2009, 06:38:04 午後 »

4.0.1 Public Beta1.2で直ってました!
http://progression.jp/ja/download/4.0.1_pb1.2/
IP記録
ページ: [1]
  印刷  
 
ジャンプ先:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!