Saturday, November 8, 2008

Notes class 6 october 14

72. textfield 1 and 73. TextField2
TextFeld is a premade class
Var mytextfield = new TextField();
Mytextfield.property = “string”

Text fields don’t stretch. You can set height or width or it will be an autoSize where it will stretch to the width of the contained text. Use border properties to see the position of the field while working with it and turn it off when done, like tables in html.



74. text format
Is a different class. Like a style class that you use to define what the text should look like. Set textfield and text format to private variables.
Private variables are accessible to the whole class. Private variables are available to other classes.

This file has non-embedded fonts.
Set text field properties
selectable = false; means others can’t select and alter it.


Last command has setTextFormat(with name of textFormat object) to set the font. It has to be after the text is added not before. The style is not sticky this way. The traditional format is not explicitly set. If you forget the order you need to find a reference to get it right.


75 text format 2
Lots of formatting in this file. A lot like using style sheets. Size is in pixels. Non-embeded font can set to bold or ital, etc. flash needs embedded faces if you want to rotate them. Non-embedded fonts will simply disappear if you set the rotation to something other than 0. can’t rotate preloaders because the fonts aren’t embedded while the preload is loading fonts. Can’t fade in or out, either.

76. text format 3
Leading is a pixel value. wordWrap = true; will set the text to wrap to the filed. Stretches like html to a set width but autosize will allow it to build vertically. Leading is the space between the lines. Can be negative to tighten lines if you want. There is kerning value but only for embedded fonts. Text formats gives tight typographic control. Can set custom anti-aliasing for different sizes of text. Flash handles embedded fonts really well.


77. font embedding
Add the font within the library. All the characters of the font will be available. CJK font will be a lot bigger 4-12 megabites. A western font will add about 20 k to the flash file. Embed the bold and italic as separate classes. All the sizes are available once they are in there. There are techniques for downloading the fonts and getting them later. When you set the linkage it will instantiate the font like the first black boxes were instantiated.

Make helv and clarendon as embedded fonts through the library making them instantiate. Adobe help for embedding fonts into flash using an import-type command has errors. There is one way to do it and Brian knows how to do it. Maybe he will tell us.

Class in library called clarendon. Make = new clarendon()
In myTextFormat ad parameters
Final one
myTextFormat.font = myfont.fontName
the name is already part of the font and the above command will pull it out.

myTextfield.antiAliasType = antiAliasType.ADVANCED;


78. font embedding 2
This one has kerning and letterspacing (trackint). Kerning is true or false. Antialiasing is attatched to the text field, not the format. Format is the style. Textfield is the engine thar renders it. Custom antialiasing is within the text field. To decide what you want to use do it within the flash timeline. Go to properties palette and select antilalis popup menu and choose custom. Use the sliders to choose the values that look good and write down the numbers to put in the antialiasing thickness and sharpmess value fields. You can use the type without setting the custom if you have special problems. White on dark background or very small fonts can have display problems that can be fixed with these commands.

79. font layout
Library has 2 fonts. Make TextField like divs in html. Has 2 fields and to textFormats
Stick the fonts within the class function. Make a thin format and a bold format. Now that’s done. It’s hard to make a word within a paragraph in a different font style is a special case that’s a little hard.

80. font layout 2
Same as 78 but title is set to an x and y position and the text box sets to (mytitle. Y + my.title.height - 5)
Will make the text field measure down from the title no matter if it wraps to more than 1 line. Text boxes are normally flexible to wrapping. Set properties of subsequent text boxes based on the boxes above them. Is like relative positioning in html setting each object based on the positioning of the ones above them. You can write a function to talk to text class variables.

Ape physics library can make circles with gravity and such. Cool.


81. advanced text formats
The flash help is wrong about this stuff.
File is the same as the above 2. last few lines has a way to set the bold for a few characters first set the body font and then add the bold using character count (boldFormat, 10, 50) .

82. advanced text formatting 2
2 variables. Using text:String = “”;
Like an array for text. Use a command text1 + text2. trace will ask to find the characters in the string. Then tell the bold to find the string, start at 0, text1.length will make the second string bold.

That part goes after
trace(text1.length,text2.length);
use it if you’re using a database or xml.
A lot of xml in the world is dynamically generated.

83. text input
Has new text field called inputBox
Has textFieldType.INPUT; sets text field to input box.
Can add a listener to it. It has a border so you can see it and people will know it is an input field. The event listener here is (keyboardEvent.KEY_DOEN, changeText);
inputBox.text is like a variable in that it changes . the listener doesn’t make it change but it allows you to know if a key is pressed it runs the “changeText” function that is at the bottom of the page. All the cool stuff is stored in this event with all the …

charCode == 13 is the enter key.
This file also shows the input box putting the characters entered into the formatted text area once you push the enter key.

defaultTextFormat = thinformat; is a way to get the formatting of the text to load even though it’s not in the correct order. See one of the early examples above to understand what I mean here.


84. class references getting classes to talk to each other.
Class references. Can generate custom events just like mouse events. Can have listeners waiting for special events.
Now 2 input boxes for input and main text. Input text has text field and myParent:mainText. This makes a variable designed to hold the other kind of text. Can’t make an input text class without making it pass a reference of a class called main_text. It expects to have a reference to whoever made it. Input text box changes the main text box. Put an instance of the input class onto the stage.

inputBox = new input_text(this); makes the input box on the stage. Think of it like it’s black_box. The input class lets you put instances of input_text onto the stage. It does all that sprite does plus some extra things that are added in the input_text class. The class has the intelligence. The new input box in the main_text class needs to know who made it.

Thekeyboard event listener is in input_text class allows the


85. custom events
84 = direct connections to classes
85 = wireless connections to classes using events, mouse and keyboard.
Public static … etc.

dispatchEvent(new Event(TEXT_CHANGE);
CONSTANTS SET IN ALL CAPS. MEANS YOU CAN’T CHANGE THE VARIABLE.

Class_name.CONSTANT_NAME

In this case input_text yells really loud when enter is pushed and if anything is listening it can hear it. It broadcasts. It doesn’t need to know who is listening. It needs some reference for it to listen to. Jason askes for a really simple example using the black box class to simplify the sample.

Var newText changes the input box to the varialble newtext. Inputbox traces “Custom Event” 85 is broadcasters. It doesn’t know who is listening. All oop have broadcasters.



86. video 1
Video and sound are conceptually similar. Video streams. Point to a flv file and it will play live over the internet. Use flash cs3 video encoder program that comes with flash to mash up the video. Won’t read in quicktime. Vlc player can play flv files. Flv is flash video encoded files. Utube is built on flv.

Flv 5 mb file is compressed in the folder. It streams. Memorize the things. 3 class variables. netStream
Video
NetConnection

Video s the window the video plays in
Netstream is the data hose that controls the data and info about the data. It’s the content.
Netconnection is video connection that define the connection to the flash server. proprietary servers. So you have to set the netconnection to null since there is little chance that you bought the expensive adobe server.

Next make netstream to nsVideo

vFLV = new Video(); is new video window.
AddChild
vFLV


Video scales t default size. The window is the thing on the stage the video plays into. Netconnection is the data streaming to the window.



87. video

Every video has metadata. It doesn’t show up on the stage immediately in streaming video. Metadata event is not handled the way the other events are handles. Brian has cut and paste code here to make the metadata nsVideo.client = clientObject;

It calls th private function below that calls the metadata length, height and width. The object works like an event in this case, like an event listener.
Then the code sets the width and height to the size of the video and then puts it in the center of the stage. Set the video visibility to false until the metadata shows up. Can lose some of the video. Can start it loading but not playing.
onMetaData function is at the bottom of the main_text class page.

88. pausing video
Mybox class had width, height, color.
This is a generic box button engine. Can draw different size and color boxes. Main class has the same as previous video file, but makes new box to make a button. Add to stage and event listener that will pause the movie. With pauseMovie function that asks the video to pause.

Remember to change main_text private var from play_button to pause_button.

89. pausing video 2
Plays and pauses but there is a little more to
nsVideo. Resume restarts the video
nsVideo.seek(current_position);

saving the current position in a variable to ask the restartMovie to the current position and play from there. Resume starts playing seek finds a particular location.



90. Video scrubbing
Make new scrubber in the main_text 200 wide, 20 tall. All the rest is the same

scrubVideo function.
Listens for mouse events. The gray bar has localX and localY and also by the stageX and stageY. So by loking at where the mouse is on the gray bar you can see where it goes.
Normalize to know mobie duration and crubber.width to find the position of the mouse vs the frame of the movie to jump to different locations of the video based on the position of the mouse. There is x time in ms and distance by width in pixels to move to the play head to corresponding points in the time of the movie. Like the quicktime scrubber bar.

The trace action with all the math functions checks the math of the scrubber bar.


91. webcam
Webcam uses video window. Throw in flash security stuff at the top. Camera = getCamera like microphone = getMicrophone.

Then it plays the webcamera to the flash player. Can get activity based on the movement in the camera. Can set tolerance of the camera like you can set gain on microphone.

Flash bitmap api allows manipulation of pixels.




Next week sensors and phigits boards to take and send data.
Work on sound player add text.
Final project something that can be done in pieces and steps. Don’t start with a gigantic feature list. Load something xml then add music player then something else etc.



Ape 2D physics engine. Create particles and add to groups. Changes the way objects interact with the screen. Can make a game car this way.

No comments: