ReferenceError:错误#1069:在String上找不到属性0,并且没有默认值

时间:2015-07-04 10:41:46

标签: actionscript

他,大家好。我是ActionScript 3的新手,我不明白我的错误在哪里。

private function InitLetter(event:MouseEvent):void {
    this.letter = event.target.name;
}

事件监听器的InitLetter函数是

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;


public class MainActivity extends ActionBarActivity {


    private FragmentManager mFragmentManager;

    private Fragment_1to6 f1to6;
    private Fragment_7to12 f7to12;
    private buttonsFragment mButtonsFragment;

    private FrameLayout relative1;
    private RelativeLayout relative2;

    float x1, x2;
    float y1, y2;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mFragmentManager = getFragmentManager();

        relative1 = (FrameLayout) findViewById(R.id.fragment_container);
        relative2 = (RelativeLayout) findViewById(R.id.fragment_7to12);


        if (!isInTwoPaneMode()) {
            mButtonsFragment = (buttonsFragment) mFragmentManager.findFragmentById(R.id.fragment_buttons);
            FragmentTransaction ft = mFragmentManager.beginTransaction();
            ft.replace(R.id.fragment_container, new Fragment_1to6());
            ft.addToBackStack(null);
            ft.commit();

            relative1.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    switch (event.getAction()) {

                        case MotionEvent.ACTION_DOWN: {
                            x1 = event.getX();
                            y1 = event.getY();
                            break;
                        }

                        case MotionEvent.ACTION_UP: {
                            x2 = event.getX();
                            y2 = event.getY();

                            // right to left
                            if (x1 > x2) {
                                    changeToSecondFrag();

                                    mFragmentManager.executePendingTransactions();

                                return true;
                            } if (x1 < x2) {

                                    changeToFirstFrag();
                                    mFragmentManager.executePendingTransactions();

                                return true;

                            } break;

                        }
                    }
                    return true;
                }
            });

        } else {
            mButtonsFragment = (buttonsFragment) mFragmentManager.findFragmentById(R.id.fragment_buttons);
            f1to6 = (Fragment_1to6) mFragmentManager.findFragmentById(R.id.fragment_1to6);


            f7to12 = (Fragment_7to12) mFragmentManager.findFragmentById(R.id.fragment_7to12);


        }

        }



    private boolean isInTwoPaneMode(){
    return findViewById(R.id.fragment_container) == null;
}

    public void changeToSecondFrag(){

            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.replace(R.id.fragment_container, f7to12);
            ft.addToBackStack(null);
            ft.commit();

    } public void changeToFirstFrag(){

            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.replace(R.id.fragment_container, f1to6);
            ft.addToBackStack(null);
            ft.commit();

    }


        }

我收到的错误是“ReferenceError:错误#1069:在字符串上找不到属性0且没有默认值。”

为什么我无法通过event.target获取按钮的访问名称。为什么?非常感谢你。

1 个答案:

答案 0 :(得分:0)

您的问题出现在您的主要Hangman课程中,CheckLetter()函数:

for (var i:int = 0; i < word.length; i++)
{
    if (word[i] == currentLetter)       // word is a String and not an Array
    {
        // ...
    }
}

在这里你应该知道要从String中获取char,我们使用string.charAt(i),如果你想使用Array对象,你可以这样做:

word:Array = "word".split("");     // gives : ["w", "o", "r", "d"]

另外,我不知道你为什么要使用它:setInterval(PlayGame,100);,通常你可以在用户输入新信时检查单词,而不是每100毫秒!甚至你必须使用它(在另一种情况下),最好使用TimerEvent.ENTER_FRAME ......

希望可以提供帮助。