Jumat, 23 Mei 2008

Scrollbars for Dynamic Text

Introduction

Probably one of the most highly used components on any web page, is the scrollbar. It's far too difficult to fit that much text onto a single page, and it's even harder to do so into the smaller areas SWiSH sites have to work with. So, instead of dividing a large body of text into multiple pages, you can put it into a dynamic text field and add your own scrollbar!

IMPORTANT

Changes in the way SWiSH Max2 handles text objects will either require a change to the actionscript, a change in the export settings, or both. Textfield properties such as scroll, maxscroll, and bottomScroll can be accessed either by using the _text property (eg. myText._text.maxscroll) or by exposing SWF6 properties in the export settings.

So, before continuing with the tutorial, be sure to make this change:

Modify Menu -> Movie Properties -> Export Settings for Movie -> SWF -> Expose SWF6 Properties
Modify Menu -> Movie Properties -> Export Settings for Movie -> SWF -> SWF version to export: SWF6 (or higher)

Setting Up

I am going to try to give specific instructions on re-creating the example shown above. In your own projects, you can obviously use any design style you want - change the positions, sizes, colors, etc. This scrollbar is designed specifically to work with Dynamic text objects. It will not work for scrolling MovieClips or Static Text.

1) Start a new movie (Modify menu | Movie Properties):
Width: 300
Height: 200

2) Modify menu | Movie Properties | Export Settings for Movie
Expose SWF6 Properties

3) Draw a text object on the Stage, then open the Properties panel (it may help to switch to the Selection Tool before changing the object's properties):
Name: textBox
Target: Yes
Font: _sans
Size: 10
Color: Black
Style: Bold
Type: Dynamic
Width: 236
Lines: 12 (disable Auto-size height)
Border: Yes (Black border with white background)



4) Transform Panel
X: 24
Y: 27
O=X: Yes
Transformation point (anchor): Top-Left



Note: Changing an object's _width and/or _height properties on the Transform panel will also change its _xscale and/or _yscale values as well. To maintain 100% scale, use the Reshape panel to alter its unscaled width/unscaled height.

5) Insert a lot of text into this dynamic textfield. If you want, you can generate a couple of paragraphs with the Lorem Ipsum generator.

6) Next, use the rectangle tool and draw a shape on the Stage. Use the Reshape panel to give it these properties:
X: 260
Y: 27
Unscaled Width: 16
Unscaled Height: 16
Transformation Point: Top-Left
O=X: Yes



7) Copy this rectangle shape (Edit Menu -> Copy Object). Then paste it in place (Edit Menu -> Paste in Place).

8) Use the Reshape panel to give it these properties:
X: 260
Y: 43
Unscaled Width: 16
Unscaled Height: 116
Transformation Point: Top-Left
O=X: Yes

9) Use the Properties panel to name it track and select the 'Target' option (you can come back after Step 10 and give the track object a different color, if you'd like).



10) Copy this object and paste it in place. Use the Reshape panel to change its height to 24.

11) Use the Properties panel to change its name to thumb.



12) Next, copy the first rectangle shape (the smaller square) and paste it in place. Use the Reshape panel to change its Y position to 159.



13) Optionally, add an up/down arrow icon to the first and last shapes (I used a bitmap font, but you can use the bezier tool or any dingbat font you want).

Grouping the Pieces

14) Select the first rectangle (smaller square at the top) and any arrow icon you may have placed over it. Group these as a MovieClip (Modify Menu -> Grouping -> Group as MovieClip ). Then name it upScroll on the Properties panel.



15) Repeat the last step for the bottom square and arrow icon, and name it downScroll on the Properties panel.



16) Select the thumb object, group it by itself as a MovieClip and name it slider on the Properties panel.



17) Next, hold down the CTRL key and select both the slider MovieClip and the track object. Group these as a MovieClip and name it scrollBar on the Properties panel.



Scripting the Scrollbar

18) Next, open the scrollBar and slider MovieClips and select the thumb object. Open the Script panel and enter this script:
on (press) {
this.startDragUnlocked(0,0,0,_parent.track._y + (_parent.track._height - this._height));
this.doScroll = setInterval(
function() {
var scrollFactor:Number = _parent._parent.textBox.maxscroll / (_parent.track._height - _height);
_parent._parent.textBox.scroll = Math.ceil(_y * scrollFactor);
updateAfterEvent();
}, 50
);
}
on (release,releaseOutside) {
stopDrag();
clearInterval(doScroll);
}


Explanation: Okay, without getting overly complicated ... setInterval is a slightly more efficient way of writing an onSelfEvent(enterFrame) Event. Instead of happening on every frame (which depends on the frame rate of the movie), the 'function' defined will execute on a set number of milliseconds. In this case, the code fires every 50 milliseconds (although, it's not an exact science). The code calculates the amount of scroll based on comparing the maximum scroll value with the available scroll area (while the user is dragging the slider). When the button is released, the interval is cleared (deleted).



Scripting the Scroll Buttons

19) Open the upScroll MovieClip and select the rectangle shape (should be the bottom object inside the MovieClip). This will be the 'hotspot' for the button. Open the Script panel, and enter the following code:
on (press) {
this.doScroll = setInterval(
function() {
_parent.textBox.scroll -= 1;
var scrollPercent:Number = _parent.textBox.scroll / _parent.textBox.maxscroll;
if (_parent.textBox.scroll == 1) {
_parent.scrollBar.slider._y = 0;
} else if (_parent.textBox.scroll == _parent.textBox.maxscroll){
_parent.scrollBar.slider._y = _parent.scrollBar.track._height - _parent.scrollBar.slider._height;
} else {
_parent.scrollBar.slider._y = (_parent.scrollBar.track._height - _parent.scrollBar.slider._height) * scrollPercent;
}
updateAfterEvent();
}, 50
);
}
on (release,releaseOutside) {
clearInterval(doScroll);
}


Explanation: This code is nearly the same as the slider's code; however, this works a little backward in comparison. The buttons will always scroll exactly 1 line of text on each Interval. At the same time, it takes the current scroll position and compares it with the maximum scroll value and calculates how much to move the slider.



20) Open the downScroll MovieClip and select the rectangle shape (should be the bottom object inside the MovieClip). This will be the 'hotspot' for the button. Open the Script panel, and enter the following code:
on (press) {
this.doScroll = setInterval(
function() {
_parent.textBox.scroll += 1;
var scrollPercent:Number = _parent.textBox.scroll / _parent.textBox.maxscroll;
if (_parent.textBox.scroll == 1) {
_parent.scrollBar.slider._y = 0;
} else if (_parent.textBox.scroll == _parent.textBox.maxscroll){
_parent.scrollBar.slider._y = _parent.scrollBar.track._height - _parent.scrollBar.slider._height;
} else {
_parent.scrollBar.slider._y = (_parent.scrollBar.track._height - _parent.scrollBar.slider._height) * scrollPercent;
}
updateAfterEvent();
}, 50
);
}
on (release,releaseOutside) {
clearInterval(doScroll);
}


Explanation: This code is the same as the upScroll MovieClip's code. The only difference is the first line inside the function - it scrolls +1 rather than -1.



Note: If you want either of those buttons (upScroll or downScroll) to scroll through the text faster or slower, you can adjust the "50" at the bottom of the SetInterval function. A lower number will scroll faster, while a higher number will scroll slower

At this point, you should have a fully functioning scrollbar component. You can take it a few steps further if you'd like; I just wanted to focus on the basics. You could make the height of the slider more dynamic by comparing the total lines of text and inversely altering the height of the slider (more text = smaller slider, and vice versa). You could also add script to the track object to make it act as a button, too (a "scroll here" effect). There are countless possibilities. This is by no means the only way to create a scrollbar component ... it's just the one I decided to write about =)

Linking to Other Web Pages

Introduction

A short tutorial showing how to create hyperlinks to other web pages (URLs). The same method can be used to create links to external files - such as ZIP, DOC, PDF, MP3, etc.

Important

There can be problems testing external links locally (from your computer). One of the features of the latest Flash Player is heightened security. Basically, when you install it, you need to visit Adobe/Macromedia's online settings manager to choose and apply your settings. This should only need to be done once - on any computer you use for development and testing.

This thread in our forums covers the topic in some detail and provides links to the settings manager:
http://forums.swishzone.com/index.php?showtopic=26790

When creating links to external files such as PDF documents, keep in mind that the file will most likely open in the default application set on the viewer's computer. In the case of PDF files, creating a link to it will usually open the file in the browser with Acrobat Reader. If you link to an MP3 file, it will probably open in the viewer's media player (WinAmp, Windows Media Player, Quicktime, etc.) If you want to allow the user to save the file to their computer, it is recommended to ZIP (or RAR) the file and link to that instead.

Setting Up

The actionscript for hyperlinks is very simple. I'll show how to do it using point-and-click methods with the Assist Pane on the Script panel.
You can turn any shape, image, text, object, or MovieClip into a hyperlink. So, open a new file in SWiSH Max2 and draw a rectangle shape on the Layout. Select that shape and open the Script panel.

1) Add Script -> Events -> Button -> on (release)
2) Add Script -> Browser/Network -> getURL(...)
3) On the Assist Pane, type in the web page you want to open in the URL field.
4) In the Window field, you can select (or type in) a target frame. The default options _self and _blank refer to the browser window itself. If you select _self, it will open the URL in the same browser window. If you select _blank, it will open a new browser window and go to the URL provided. The options _top and _parent refer to Framesets (HTML Frames). If you are using a frameset and want to open a URL in a specific frame, you will need to know the exact name of that frame (written in the HTML frameset code). Whatever name is in the HTML is what you would type into the Window field.

You should end up with a script similar to this:
on (release)
{
getURL("http://www.example.com", "_blank");
}

CTL

Contextual Teaching and Learning (CTL) helps us relate subject matter content to real world situations and motivate students to make connections between knowledge and its applications to their lives as family members, citizens, and workers and engage in the hard work that learning requires. Contextual teaching and learning strategies:
[1] Problem-based.
[2] Using multiple contexts.
[3] Drawing upon student diversity.
[4] Supporting self-regulated learning.
[5] Using interdependent learning groups.
[6] Employing authentic assessment.

Inquiry Based Lerning

"Inquiry" is defined as "a seeking for truth, information, or knowledge -- seeking information by questioning." Individuals carry on the process of inquiry from the time they are born until they die. This is true even though they might not reflect upon the process. Infants begin to make sense of the world by inquiring. From birth, babies observe faces that come near, they grasp objects, they put things in their mouths, and they turn toward voices. The process of inquiring begins with gathering information and data through applying the human senses -- seeing, hearing, touching, tasting, and smelling.

A Context for Inquiry

Unfortunately, our traditional educational system has worked in a way that discourages the natural process of inquiry. Students become less prone to ask questions as they move through the grade levels. In traditional schools, students learn not to ask too many questions, instead to listen and repeat the expected answers.

Some of the discouragement of our natural inquiry process may come from a lack of understanding about the deeper nature of inquiry-based learning. There is even a tendency to view it as "fluff" learning. Effective inquiry is more than just asking questions. A complex process is involved when individuals attempt to convert information and data into useful knowledge. Useful application of inquiry learning involves several factors: a context for questions, a framework for questions, a focus for questions, and different levels of questions. Well-designed inquiry learning produces knowledge formation that can be widely applied.

Problem Based Learning

Problem-based learning (PBL) is a student-centered instructional strategy in which students collaboratively solve problems and reflect on their experiences. It was pioneered and used extensively at McMaster University, Hamilton, Ontario, Canada. Characteristics of PBL are:
[1] Learning is driven by challenging, open-ended problems.
[2] Students work in small collaborative groups.
[3] Teachers take on the role as "facilitators" of learning.

Accordingly, students are encouraged to take responsibility for their group and organize and direct the learning process with support from a tutor or instructor. Advocates of PBL claim it can be used to enhance content knowledge and foster the development of communication, problem-solving, and self-directed learning skill.

Team Game Tournament Instructions

This learning activity appeals to many different types of learner including the cooperative and the competitive learner.
Step1 Divide the class into teams of four or five. A class of 29 would have 5 teams of 5 and one team of 4.
Step 2 Distribute the Practice version of the test to each student and instruct them to answer the questions cooperatively as a team, ensuring that all team members understand how each answer was obtained. The intention is to lift the overall team performance.
Step 3 Display a copy of the answers on the OHP or data projector and get each team to check their answers and resolve any issues with their answers.
Step 4 Ask the students to sort there team on the basis of their understanding of the topic from very good understanding (A students) to poor understanding (E students). The team of 4 students will only have A to D students.
Step 5 Regroup and seat all of the A students in one area of the room, B students in another area etc.
Step 6 Give out the Test version questions to each student and instruct them to individually answer the questions under formal test conditions.
Step 7 Display a copy of the answers on the OHP or data projector and get each student to mark their answers and then to rank themselves amongst the group of students the y are grouped with. That is, the A students will rank themselves from best to worst score. The student with the best score is given a score of 5` points while the student with the lowest score is given a score of 1 point. Students with equal scores receive the same number of points (e.g. the points distribution could be 5, 4, 4, 4, 1 if three students have the same score). If there are only four students in a group, the scores will range from 5 to 2 points.
Step 8 The students recombine into their original teams and total their scores with the largest score winning. Any team with less than 5 students adds the average grade for the team to their score.

Jigsaw in 10 Easy Steps

The jigsaw classrom is very simple to use. If you're a teacher, just follow these steps:

[1] Divide students into 5- or 6-person jigsaw groups. The groups should be diverse in terms of gender, ethnicity, race, and ability.
[2] Appoint one student from each group as the leader. Initially, this person should be the most mature student in the group.
[3] Divide the day's lesson into 5-6 segments. For example, if you want history students to learn about Eleanor Roosevelt, you might divide a short biography of her into stand-alone segments on: (1) Her childhood, (2) Her family life with Franklin and their children, (3) Her life after Franklin contracted polio, (4) Her work in the White House as First Lady, and (5) Her life and work after Franklin's death.
[4] Assign each student to learn one segment, making sure students have direct access only to their own segment.
[5] Give students time to read over their segment at least twice and become familiar with it. There is no need for them to memorize it.
[6] Form temporary "expert groups" by having one student from each jigsaw group join other students assigned to the same segment. Give students in these expert groups time to discuss the main points of their segment and to rehearse the presentations they will make to their jigsaw group.
[7] Bring the students back into their jigsaw groups.
[8] Ask each student to present her or his segment to the group. Encourage others in the group to ask questions for clarification.
[8] Float from group to group, observing the process. If any group is having trouble (e.g., a member is dominating or disruptive), make an appropriate intervention. Eventually, it's best for the group leader to handle this task. Leaders can be trained by whispering an instruction on how to intervene, until the leader gets the hang of it.
[10] At the end of the session, give a quiz on the material so that students quickly come to realize that these sessions are not just fun and games but really count.