# Egret FAQ
### Q1. Main.ts 這支是怎麼被啟動的?我能更改啟動的 ts 對象嗎
:::success
**index.html** 裡的 **data-entry-class** 決定了入口(預設為 Main),你可以在這裡修改
:::

### Q2. 創建專案時的 Game 項目、EUI 項目有什麼不同
:::success
引入的 Library 不同,沒有互相包含,但也可以混用,只是需要 **手動引入** 對應的 Libs,以目前專案集合 UI 的特性,比較適合直接使用 **EUI** 創建項目
:::
### Q2a. 如果創建專案忘了勾選 Game 項目, 要如何補上去
:::success
* 開啟 **egretProperties.json** 並且在 **module** 底下新增以下內容
```
{
"name": "game"
}
```
* 打開 console 執行 **egret build -e**
* 完成後, 會在專案底下的 **libs/modules** 出現 **game** 資料夾
:::
### Q3. createChildren 的觸發時機
:::success
用於手動創建 Skin 內容(即未綁定 Skin)
**唯一** 觸發點為該 eui.UILayer 在 stage 創建前,**比 constructor 早**
:::
### Q4. childrenCreated 的觸發時機
:::success
UILayer 創建完成時觸發此函數,可用來覆寫一些初始化
**唯一** 觸發點為該 eui.UILayer 在 stage 創建完成時,**比 constructor 晚**
:::
### Q5. partAdded 觸發時機
:::success
只要綁定的 Skin (exml) 有設定 UI 的 ID 就會觸發 partAdded,這個方法主要是讓你可以對 UI 做一些初始化設定,而不是在 Skin 端寫死
:::
```
protected partAdded(partName: string, instance: any): void
```
### Q6. 如何取得 skin 上多個連續元件
:::success
透過 **this[名稱]** 來取得
假設有5個的 eui.Rect 元件, 名稱是 obj0, obj1....以此類推
:::
```
//VS可自動辨別 target 的型別是 eui.Rect
let target = this["obj0"];
for(let i = 0; i < 5; i++){
//VS無法辨識型別, 會標示成 any
//建議把型別標上去
let target2 : eui.Rect = this["obj" + i];
}
```
---
### Q7. 如何有效的進行 debug
:::success
參考 [Get Started with Debugging JavaScript in Chrome DevTools](https://developers.google.com/web/tools/chrome-devtools/javascript)
:::
---
### Q8. screen.width 拿到的寬度與實際顯示寬度不符
:::success
windows作業系統有調過文字大小,會直接影響到 screen.width
需要拿 window.devicePixelRatio 再做一次計算
:::
---
### Q9. 如何規避 Array.isArray() 引發的錯誤
:::info
範例
```
interface ABC{
name: string;
value: number;
}
let list:ABC[] = [{"name":"A", "value":1}];
if(Array.isArray(list))
console.log("isArray, " + list[0].name);
else
console.log("notArray, " + list[0].name);
```
:::
:::danger
發生問題
* else 區塊會找不到 list[0].name
:::
:::success
解決方法
* 不要在條件式判斷 Array.isArray, 把結果指定給一個 boolean 區域變數
```
let isArray: boolean = Array.isArray(list);
if(isArray)
console.log("isArray, " + list[0].name);
else
console.log("notArray, " + list[0].name);
```
:::
---
###### tags: `Egret`