Download - Programming Your App’s Memory 靜宜大學資管系 楊子青
靜宜大學資管系 楊子青 1
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.
靜宜大學資管系 楊子青 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.
靜宜大學資管系 楊子青 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.
靜宜大學資管系 楊子青 5
Modifying the memory slots in the property form to change the app’s appearance
靜宜大學資管系 楊子青 6
2. Variables
• Defining Variables
• Setting and getting a Variable
• Setting a Variable to an Expression– Incrementing a Variable
– Building Complex Expressions
• Displaying Variables
靜宜大學資管系 楊子青 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.
靜宜大學資管系 楊子青 8
Defining Variables
1. 拖曳出 initialize global name to
靜宜大學資管系 楊子青 9
Defining Variables
2. 設定變數名稱
3. 設定初值
靜宜大學資管系 楊子青 10
2.2 Setting and getting a Variable
• 設定 ( 變更 ) 變數值
選擇變數名稱
靜宜大學資管系 楊子青 11
Setting and getting a Variable
• 取得變數值
選擇變數名稱
靜宜大學資管系 楊子青 12
2.3 Setting a Variable to an Expression
• Incrementing a Variable
• Building Complex Expressions
靜宜大學資管系 楊子青 13
Math drawer
• In the Math drawer, App Inventor provides a wide range of mathematical functions.
靜宜大學資管系 楊子青 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.
靜宜大學資管系 楊子青 15
HelloPurr_Extend
靜宜大學資管系 楊子青 16
1. 複製專案進行修改• 開啟 HelloPurr 專案, Save as 為 HelloPurr_Extend
靜宜大學資管系 楊子青 17Media 部分,以 Upload File 加入獅子圖片 (lion.jpg) 與獅吼聲音 (roar.m
p3)
靜宜大學資管系 楊子青 18
回顧: LabelName 的 Text 屬性,決定顯示文字內容
靜宜大學資管系 楊子青 19
回顧: Button1 的 Image 屬性,決定該按鈕的長相 ( 顯示哪張圖片 )
靜宜大學資管系 楊子青 20
回顧: Sound1 的 Source 屬性,決定播放哪個聲音檔
靜宜大學資管系 楊子青 21
如何動態調整顯示文字?圖片?聲音?
靜宜大學資管系 楊子青 22
執行結果:初次播放 roar.mp3 發生 error
靜宜大學資管系 楊子青 23
Google 找解決方法
靜宜大學資管系 楊子青 24
Screen1.Initialize
靜宜大學資管系 楊子青 25
鱷魚拔牙整人玩具http://www.i-gamer.net/play/2978.html
靜宜大學資管系 楊子青 26
2. 按圖片,第 6 次出現獅子
靜宜大學資管系 楊子青 27
3. 隨機第 2-6 次出現獅子