How-to

How to set up a webpage for the iphone :: How to

In case anyone is interested in setting up a web page for the iphone, this is the template I used for all my pages. You can add more code if you like but this is how I have been generally setting up my pages.

How to:

1) Create a new document and save it as index.html.

2) Copy and paste this code into your document.

3) Start developing between the <body> tags.

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
<head>
<meta name=”viewport” content=”width=device-width; initial-scale=1.0; maximum-scale=1.0;”>

<link rel=”apple-touch-icon” href=”images/myiphone_ico.png”/>

<link href=”../styles/iphone_portrait.css” rel=”stylesheet” type=”text/css” media=”screen” id=”orient_css”>
<link href=”../styles/styles.css” rel=”stylesheet” type=”text/css” media=”screen”/>

<script type=”text/javascript” src=”js/script.js”> </script>

<script type=”text/javascript”>
<!– Orientation Script
function orient(){
switch(window.orientation){
case 0: document.getElementById(“orient_css”).href = “../styles/iphone_portrait.css”;
break;

case -90: document.getElementById(“orient_css”).href = “../styles/iphone_landscape.css”;
break;

case 90: document.getElementById(“orient_css”).href = “../styles/iphone_landscape.css”;
break;

}
}
window.onload = orient();
–>
</script>

<title></title>

</head>

<body onorientationchange=”orient();”>

</body>
</html>

How to #2 – make single page website using TweenMax

LOTS OF CODE! But the effect is cool and could be used for a lot of things.

Because the interaction on my one thread of my application was fairly basic since it had to be for a kid to be able to navigate, and decide I would put a how to from the website I am designing for my independent study, which still could be useful for other things than just a website.

My website is a single page site, with a top navigation that navigates up and down the site to each section for teachers, students and parents.

So my issue was trying to get the navigation to be able to go to each section with an ease. For something like this, it is all about positioning. Below is a list of my process

1) designed most of the single page website in photoshop and brought it into flash and made it its own movie clip (website_mc) and exported it for actionscript.

2) The things I left on the main stage were the navigation and the background.

3) I then put buttons on the navigation and wrote the following script: (way more then 4 lines of code but it’s better to give the whole idea so that it’s better understood

import com.greensock.*;
import com.greensock.easing.*; // important to bring in the greensock easing and other files from the “com” folder we downloaded to make the transition up and down the page smooth
var website:MovieClip = new website_mc(); // bring in a new variable ( website_mc ) to the stage
var xPos = stage.stageWidth / 2;
addChild (website); // add the newly named child to the stage. ( the actual website_mc does not appear on the stage , it shows up once file is rendered)
setChildIndex(website,1);
// let’s say you want to add a button for the teacher section, so that once “teachers” is clicked, the site literally moves down to the teacher section
teachers_btn.addEventListener(MouseEvent.CLICK, onTeachersClick);
// set the main (default or home) position for the page first
website.x = xPos; //xPos basically locks the movie clip so that it will not move along the x-axis
website.y = 300;
// this function is saying, that when Teachers is clicked, the child named “website” will literally move up to a new position, as to reveal the “teacher’s” section on the main stage. So it moves from y-position 300 to y-position -200.85. You would change the position to whatever you want based on the properties.
function onTeachersClick(event:MouseEvent) :void{
//website.x = xPos;
//website.y = -200.85;
TweenMax.to(website, 1, {x:xPos, y:-200.85, ease:Circ.easeOut}); // adding the TweenMax ease makes the transition smooth.
}

How to #1 frame change after movie clip

Okay so this may sound a little complicated, but this is a how to on how to progress to the next frame in the main timeline once a movie clip has finished within a movie clip that is embedded in the main timeline. There are definitely easier ways to say that I’m sure.

But, basically for example with my app. I wanted the a frame change in my main timeline after at least one of the items on the recycling team (bottle, can or paper) reached 3 tick marks. So, basically, at the end of the movie clip you want the frame to change, you would put:

import flash.display.MovieClip;
MovieClip(root).gotoAndPlay(5);

The “import flash.display.MovieClip;” is telling flash to reference this movie clip once you get the main timeline.
And then “MovieClip(root).gotoAndPlay(5);” is telling flash to play the movie clip in the root menu (main timeline) and once it finished, to go to and play the next frame you want.

How-To #2 Make Things Easier for yourself

A little trick I did while creating my presentation was the way I named files. For instance, when I clicked on “during_btn” in “during_mc”  it would go to and play “during_kf.” By making all these titles the same based on what keyframe it was going to end up playing, it was super easier to punch them in to the code. Before this, my instance names for things were all over the place and I had to double and triple  check everything to make sure if it was named right in order to play.
Another simple trick, but it saved me a lot of time.

How-to #1

Alright, so I was a little late to realize how to make a button in Flash without embedding movie clip inside of movie clip inside of movie clip.

This might seem really simple now, but I had no idea how to add buttons to go to another frame on the same timeline. Here’s the code:
your_mc.addEventListener(MouseEvent.CLICK, onyour_mcClick);

function onyour_mcClick(event:MouseEvent):void {
//trace (“click”);
this.gotoAndPlay(“keyframe”);
}

The key here is “THIS.gotoAndPlay,” which denotes the same timeline. You could also put the name of a movie clip here is you wanted to put movie clip inside of movie clip.

Simple, I know, but not if you don’t know how to do it!

Flash demo : tween with code

The Flash plugin is required to view this object.

To learn more about TweenMax and TweenLite, go to

To learn about the flash transition class

Draw a rectangle the size of the screen (240 x 380px) on the stage.

Convert the rectangle to an mc named “box”.

Double click on the mc to get to the box timeline.

Create a new layer named “button”.

Draw a rectangle and convert it to a button named “circle_btn”.

Name the instance of the button “circle_btn” in the properties inspector.

Go back to the main timeline and name the instance of the box on the stage “box” in the properties inspector.

Create a new layer named “actions” and paste the following code in the actions palette:

import com.greensock.*;
import com.greensock.easing.*;

// ————VARIABLES——————————————–

//object position variables
var xPos:Number = stage.stageWidth / 2;
var yPos:Number = stage.stageHeight / 2;

// ————ADD OBJECT TO STAGE———————————-
/*
//add child to stage variables
var box:MovieClip = new box_mc();

//add the movieclip from the library to the stage
addChild (box);
*/

// ————SET INITIAL STAGE POSITIONS——————————————–
//object name and postion (refer to position variables above)
box.x = xPos;
box.y = yPos;

// ————LISTENER AND FUNCTION FOR CLICK ON BOX——————————————–
box.circle_btn.addEventListener(MouseEvent.CLICK, onCircleClick);

function onCircleClick (event:Event):void{
//add tween for box currently on stage
TweenMax.to(box, 1, {x:-120, y:yPos, alpha:1, ease:Circ.easeOut, delay:.15});
}

Flash Demo : drag and drop objects

The Flash plugin is required to view this object.

Drag the same pink and black box mc’s from the previous demo onto the stage.

Name them “box_gray” and “box_pink” respectively.

Create a new layer named “actions” and paste the following code into the actions palette:

box_gray.addEventListener(MouseEvent.MOUSE_DOWN, dragGray);
box_gray.addEventListener(MouseEvent.MOUSE_UP, dropGray);
box_pink.addEventListener(MouseEvent.MOUSE_DOWN, dragPink);
box_pink.addEventListener(MouseEvent.MOUSE_UP, dropPink);

//box_gray.addEventListener(Event.ENTER_FRAME, enterGray);
box_pink.addEventListener(Event.ENTER_FRAME, hit);

function dragGray (event:MouseEvent) : void {
event.target.startDrag();
}

function dropGray (event:MouseEvent) : void {
event.target.stopDrag();

}

function dragPink (event:MouseEvent) : void {
event.target.startDrag();
}

function dropPink (event:MouseEvent) : void {
event.target.stopDrag();

}

function hit (event:Event) : void {
if (box_pink.hitTestObject(box_gray)) {
box_gray.alpha = .25;
} else {
box_gray.alpha = 1;
}
}

Flash demo : add and remove child from stage

The Flash plugin is required to view this object.

Create a pink box on the stage and convert it to an mc named “box_pink”. Before clicking okay, check the radio button to “export for Actionscript”.

Create a black box on the stage and convert it to an mc named “box_black”. Before clicking okay, check the radio button to “export for Actionscript”.

Delete both instances from the stage.

Select the first keyframe in the timeline and paste the following code into the actions panel:

var boxBlk:MovieClip = new box_black();
var boxPink:MovieClip = new box_pink();

var xPos = stage.stageWidth / 2;
var yPos = stage.stageHeight / 2;

boxBlk.x = xPos;
boxBlk.y = yPos;
boxPink.x = 120;
boxPink.y = 150;

addChild (boxBlk);

boxBlk.addEventListener(MouseEvent.CLICK, onBlackClick);
boxPink.addEventListener(MouseEvent.CLICK, onPinkClick);

function onBlackClick (event:MouseEvent) : void {
removeChild (boxBlk);
addChild (boxPink);

}

function onPinkClick (event:MouseEvent) : void {
addChild (boxBlk);
removeChild (boxPink);
}

Flash Demo : animate with code

The Flash plugin is required to view this object.

Create a box on the stage and convert it to a movieClip named “box”.

Name the instance of the mc “box” using the properties inspector.

Create a new layer named “actions” and paste the following code into the actions panel:

//add child to stage variables
var box:MovieClip = new box_mc();

//add the movieclip from the library to the stage
//addChild (box);

//position box on stage
box.x = stage.stageWidth / 2;
box.y = stage.stageHeight / 2;

//scale and transparency box
box.scaleX = .25;
box.scaleY = 1;
box.alpha = .1;

//enter frame listener and function to animate when movie begins
box.addEventListener (Event.ENTER_FRAME, animate);

function animate (event:Event) : void {
event.target.scaleX += .01;
event.target.scaleY -= .01;
event.target.alpha += .05;
event.target.rotation += .5;
}

iPhone Technical Specifications

iPhone screen size is: 480-by-320-pixel resolution at 163 ppi

Find all technical specifications here.

documentation of origami skill levels

iPhone Development

10+ useful code snippets to develop iPhone friendly websites

In case anyone is interesting in developing their apps via website or are interested in developing websites in general that will work on an iphone, this is useful. I haven’t tried any of the code out yet myself but I’m sure they will work fine because this is a reputable website.

Go There –>


iPhone SDK

If anyone is interested, you can download the iphone simulator to help in development. However, there are strings attached, such as you need either Leopard or Snow Leopard to run it. If you register as an iphone developer using your Apple ID (which you need to do to download the simulator) you will have access to some files that’ll help you start in development and help answer questions that may or may not be found using Google.

Go There –>

If you work on a windows (as not every company will provide us with a nice, spiffy Macintosh such as IBM…crazy right?), I hear that this is a good simulator. You do not need to register. I have not tried it out myself yet, but will update later when I have.

Remember to use Safari if you are testing your code on your Localhost using a text based or WYSIWYG editor as that’s the browser the iPhone uses.

Tutorials for everything and anything.

Bookmark this page and refer to it when you are trying to learn anything new on the computer.

It will be your best friend

http://tutsplus.com/

Some kew ideas

Ideas: How to_

/fold origami

//skin a fish

///make your own beer

Button controlled smooth MC play/rewind

The Flash plugin is required to view this object.

1. Draw a square in the center of the stage.
Rectangle tool: turn off outline, click and drag on stage to draw.

2. Convert it to a movieclip symbol:
Right click on the square > convert to symbol > name: square_mc, “movieclip”, ok.

3. Add an invisible button inside square_mc.
Double click on the square_mc instance on the stage.
Create a new layer and call it “btn”.

With the button layer selected, draw another square or copy and paste the existing square.

Convert the shape to a button symbol called “invisible_btn”.

Double click on the button symbol you just made.
Select the “up” keyframe. Then click and drag the keyframe to the “hit” state.

Go back to the main timeline by clicking on “scene 1″ of the thread.

4. Create a short animation that will play (forward and reverse).
Select the movieclip instance on the stage.

Convert it to a movieclip symbol and call it “scale_square_mc”.

Double click on the movieclip to get to its timeline.

Create a motion tween by right clicking on the keyframe in the timeline and selecting “create motion tween”. (A 24-frame tween will automatically generate in the timeline).

Shorten the tween to 10 frames by clicking and dragging from the right edge of the tween.

With the play head on the 10th frame, use the transform tool (Q) to scale up the square. (Holding the shift key will preserve the proportion. Holding the option key will scale from the middle).

Note that a diamond keyframe appeared on the 10th frame in the timeline. You can make further adjustments to the tween using the motion editor palette.

We need to place a stop action at the end of the tween so that it doesn’t loop.
Create a layer and name it “stop”.
Right click on the 10th frame and select “insert keyframe”.

Select the keyframe.
In the actions palette, insert stop();
Note: a small “a” will appear in the timeline keyframe about the empty circle.

Go back to the main timeline (scene 1).

5. Label the instances (and the path to them) on the stage so that we can identify them in the code.
Select the movieclip on the stage.
In the properties palette, name it “scale_mc”.

Go to the “scale_square_mc” movieclip by double clicking on it on the stage.

Select the instance of “square_mc” on the stage.
In the properties palette, name it “square_mc”.

Go to the “square_mc” movieclip by double clicking on it on the stage.

Select the invisible button instance on the stage.
In the properties palette, name it “btn”.

Go back to the main timeline (scene 1).

6. Create a new layer and call it “actions”.

5. Select the actions layer frame and insert the following code using the actions palette:
//———–presets——————–
scale_mc.stop();
var rewind:Boolean = false;

//———–listeners——————–
scale_mc.addEventListener(Event.ENTER_FRAME,scaleRevFrame);

scale_mc.square_mc.btn.addEventListener(MouseEvent.ROLL_OVER,onScaleOver);
scale_mc.square_mc.btn.addEventListener(MouseEvent.ROLL_OUT,onScaleOut);

//———–functions——————–
function scaleRevFrame(event:Event):void{
if(rewind == true){
scale_mc.prevFrame();
}
}

function onScaleOver(event:MouseEvent):void{
scale_mc.play();
rewind = false;
}

function onScaleOut(event:MouseEvent):void{
rewind = true;
}

Note that there is a “var” (variable) named “rewind” in the presets. This allows us to use true/false statements (Boolean statements) to identify the condition of an instance. In other words, we can say something to the effect of, “If someone rolls over the square, then make it scale up. If someone rolls out of the square, turn it back off.”

In the listeners, we have an “ENTER_FRAME” event. It keeps track of what the movieclip instance “scale_mc” is doing.

The corresponding function for the “ENTER_FRAME” event has a conditional statement to execute. If the variable “rewind” is “true”, then go to the previous frame of scale_mc.

The other functions (onScaleOver and onScaleOut) essentially turn “rewind” on and off–they make the variable true or false. Rewind is false when someone rolls over scale_mc. Rewind is true when someone rolls out of scale_mc.

6. Save .fla and render.
The file should start with a static square in the middle. Roll over makes the square scale up smoothly, roll out makes it scale down smoothly.

Button to go to frame in movieclip

The Flash plugin is required to view this object.

1. Start with 2 buttons and one movieclip on the stage.

2. Insert the “santiago” label on the movieclip timeline.
Double click on the movieclip.
Create a new layer and name it “labels”.
On the frame you want to label, right click and select “insert keyframe”.

With the keyframe selected, go to the properties palette and name it “santiago”.

The timeline should look something like this:

3. Label the instances on the main timeline (scene 1).
Select the button instance on the stage that will take us to frame 15.
In the properties palette, name it “frame_btn”.

Select the button instance on the stage that will take us to “santiago”.
In the properties palette, name it “santiago_btn”.

Select the movieclip instance on the stage.
In the properties palette, name it “movie_mc”.

4. Create a new layer on scene 1 timeline and call it “actions”.

5. Select the actions layer frame and insert the following code using the actions palette:
//———–presets——————–
movie_mc.stop();

//———–listeners——————–
frame_btn.addEventListener(MouseEvent.CLICK, onFrameClick);
santiago_btn.addEventListener(MouseEvent.CLICK, onSantiagoClick);

//———–functions——————–
//go to and stop frame 15
function onFrameClick(event:MouseEvent):void {
movie_mc.gotoAndStop(15);
}
//go to and stop frame laneled “santiago”
function onSantiagoClick(event:MouseEvent):void {
movie_mc.gotoAndStop(“santiago”);
}

Note: If you want the mc to play, rather than stop at the destination frame, change the operation “gotoAndStop” to “gotoAndPlay“.

6. Save .fla and render.
The movie should start in a static state, go to frame 15 or frame “santiago” of the mc when you click on the corresponding button.

Button to play/stop a movieclip

The Flash plugin is required to view this object.

1. Start with a button and a movieclip on the stage.

2. Name the instance of the button.
Click on the button and name it “play_btn” in the properties palette.

3. Name the instance of the movie.
Click on the movie and name it “movie_mc” in the properties palette.

4. Create a new layer on scene 1 timeline and call it “actions”.

5. Insert the following code using the actions palette:

//———–presets——————–
movie_mc.stop();

//———–listeners——————–
play_btn.addEventListener(MouseEvent.ROLL_OVER, onPlayOver);
play_btn.addEventListener(MouseEvent.ROLL_OUT, onPlayOut);

//———–functions——————–
//roll over state
function onPlayOver(event:MouseEvent):void {
movie_mc.play();
}
//roll out state
function onPlayOut(event:MouseEvent):void {
movie_mc.stop();
}

The preset:
Stops the video from playing when the file is first loaded.

The listeners:
Identify the button instance name.add the listener (describe the event, name the function to execute);

The functions:
Name of function (describes the event):only run once {
identify the instance to effect.what it should do;
}

Note: you create the name of the of the instance and the name of the function. The instance names should match (name given to instance through properties palette and in script). The function names should match (listener and function title).

6. Save .fla and render.
The movie should start in a static state, play when you roll over the button, stop when you roll out.

Create a button symbol

The Flash plugin is required to view this object.

1. Draw a square in the center of the stage.
Rectangle tool: turn off outline, click and drag on stage to draw.

2. Convert it to a button symbol:
Right click on the square > convert to symbol > name: square_btn, “button”, ok.

3. Name button and indicate “button” type in dialog box.

(Note that the symbol is stored in the library).

4. Save and render .swf.
The cursor should change to a hand symbol when you roll over the button.

Make the button invisible (when rendered)
1. Go to the square_btn timeline.
Double click on the button symbol on the stage. (Note that it has states, not frames.)

2. Move the graphic from the “up” state to the “hit” state.
Click on the “up” keyframe to highlight it.
Click and drag keyframe to hit state.

3. Return to main stage.

Double click off stage or use embedded thread to click back to scene 1.
(Note that the button should appear as a transparent aqua square).

4. Save and render .swf.
The button should be invisible.

Set different graphics for each button state
1. Go to the square_btn timeline.
Double click on the button symbol on the stage.

2. Insert a keyframe on each state:
Right click on the timeline frame > insert keyframe.

3. Change the color of the square for each state:
Select the keyframe, then select the square.
Change the color using the color palette.

4. Return to main stage.
Double click off stage or use embedded thread to click back to scene 1.

5. Save and render .swf.

Mother App

MotherApp’s BlogEngine is the amazing tool that converts your blog and tweets into a native iPhone app in minutes with zero coding.

Simply enter your RSS feed URL, Twitter name and a description of your blog, then upload two images and voilà – you’ve created your very own iPhone app!

MotherApp takes care of submitting the app to Apple for approval and notifies you when it’s available for download.

It’s that easy!

iPhone GUI Elements Sets

There are several iPhone GUI elements that you can download as Photoshop files. Here are a few places to find them:

Teehan + Lax

Designer’s Toolbox

Kean Hui

Graffletopia