programming your app’s memory 靜宜大學資管系 楊子青

27
靜靜靜靜靜靜靜 靜靜靜 1 Programming Your App’s M emory 靜靜靜靜靜靜靜 靜靜靜

Upload: halee-mcdowell

Post on 01-Jan-2016

96 views

Category:

Documents


0 download

DESCRIPTION

Programming Your App’s Memory 靜宜大學資管系 楊子青. Memory Slots. Just as people need to remember things, so do apps. When someone tells you the phone number of a pizza place for a onetime immediate call, your brain stores it in a memory slot. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 1

Programming Your App’s Memory

靜宜大學資管系 楊子青

Page 2: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 2

Memory Slots

• Just as people need to remember things, so do apps.– When someone tells you the phone

number of a pizza place for a onetime immediate call, your brain stores it in a memory slot.

– In this chapter, you’ll learn how to set up an app’s memory, how to store information in it, and how to retrieve that information at a later time.

Page 3: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 3

Named Memory Slots

• An app’s memory consists of a set of named memory slots. – Some of these memory slots are created when you

drag a component into your app; these slots are called properties.

– You can also define named memory slots that are not associated with a particular component; these are called variables.

Page 4: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 4

1. Properties

• Components (Button, TextBox, and Canvas…)– are part of the user interface.

• Each component is completely defined by a set of properties. – The values stored in the memory slots of each prop

erty determine how the component appears.

Page 5: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 5

Modifying the memory slots in the property form to change the app’s appearance

Page 6: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 6

2. Variables

• Defining Variables

• Setting and getting a Variable

• Setting a Variable to an Expression– Incrementing a Variable

– Building Complex Expressions

• Displaying Variables

Page 7: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 7

2.1 Defining Variables

• You define a variable when your app needs to remember something that is not being stored within a component property. – For example, a game app might need to

remember what level the user has reached. • If the level number is not something the user will

see, you’d define a variable to store it.

Page 8: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 8

Defining Variables

1. 拖曳出 initialize global name to

Page 9: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 9

Defining Variables

2. 設定變數名稱

3. 設定初值

Page 10: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 10

2.2 Setting and getting a Variable

• 設定 ( 變更 ) 變數值

選擇變數名稱

Page 11: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 11

Setting and getting a Variable

• 取得變數值

選擇變數名稱

Page 12: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 12

2.3 Setting a Variable to an Expression

• Incrementing a Variable

• Building Complex Expressions

Page 13: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 13

Math drawer

• In the Math drawer, App Inventor provides a wide range of mathematical functions.

Page 14: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 14

2.4 Displaying Variables

• Changing a variable has no direct effect on the app’s appearance.– When you modify a component property, the user

interface is directly affected. This is not true for variables.

– This is one of the advantages of storing data in a variable as opposed to a component property

• it allows you to show just the data you want when you want to show it.

• It also allows you to separate the computational part of your app from the user interface, making it easier to change that user interface later.

Page 15: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 15

HelloPurr_Extend

Page 16: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 16

1. 複製專案進行修改• 開啟 HelloPurr 專案, Save as 為 HelloPurr_Extend

Page 17: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 17Media 部分,以 Upload File 加入獅子圖片 (lion.jpg) 與獅吼聲音 (roar.m

p3)

Page 18: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 18

回顧: LabelName 的 Text 屬性,決定顯示文字內容

Page 19: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 19

回顧: Button1 的 Image 屬性,決定該按鈕的長相 ( 顯示哪張圖片 )

Page 20: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 20

回顧: Sound1 的 Source 屬性,決定播放哪個聲音檔

Page 21: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 21

如何動態調整顯示文字?圖片?聲音?

Page 22: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 22

執行結果:初次播放 roar.mp3 發生 error

Page 23: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 23

Google 找解決方法

Page 24: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 24

Screen1.Initialize

Page 25: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 25

鱷魚拔牙整人玩具http://www.i-gamer.net/play/2978.html

Page 26: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 26

2. 按圖片,第 6 次出現獅子

Page 27: Programming Your App’s Memory 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 27

3. 隨機第 2-6 次出現獅子