Friday, July 16, 2010

Flash Vars Actionscript 3.0

Well, its been one year since my last post. According to my last post, this post is on Flash Vars.

Introduction:
What are Flash Vars? Flash Vars are variables programmed on the web page that can be pulled into flash and then used appropriately.

What not to use flash vars for:
If your passing any type of secure information like passwords and credit card numbers, DO NOT USE FLASH VARS. Flash Vars can be seen if a user views the source, therefore being able to see the password or credit card number and this compromises red flag compliance laws.

Lets do this:
HTML code:
add to object tag:
param name="allowScriptAccess" value="sameDomain"
param name="FlashVars" value="val1=Variable"

add to embed tag:
allowScriptAccess="sameDomain"
FlashVars="val1=Variable"
Your HTML code is now able to pull the Variable into flash!

Very simply, this is the code you need in your flash:
function retrieveFlashVar():Object{
return Object(LoaderInfo(this.LoaderInfo).parameter);
}

The function above is receiving and storing the flash vars into an object. In order to access the variable, I would recommend storing the Flash Var into a new variable within flash. You can do this with this code:

var variable1 = retrieveFlashVar().val1

I used val1 because that was the name of the flash var in the html code I provided. But if you have another name for your variable, replace val1 with whatever you named your variable.

From there, you can now use the pulled information as if it was in flash itself. Just refer to it as variable1.

Monday, June 29, 2009

Actionscripting

Hello everyone!

I see that your interested in seeing how to include AS 3.0 to your flash design. First, before we even begin with AS 3.0, let me start with talking about what AS 3.0 can do for your flash project. AS 3.0 can help your flash project to be more interactive then it already is. When you need somethign to happen when something is clicked or rolled-over or even rolled-off. Take user data and do "something" with it. Knowing that this is an art site, knowing some programming will help you in the long run.

I wanted to keep that as brief as possible so we can get to the fun part, CODING!!!!! YAY!!! :-P. Im going to go briefly over how to make a button using actionscript. Now you may be wondering (if you have used flash before) i can just use the button symbol. That would be best if you wanted to make a basic button, but if you wanted to add more animation like a seperate movie clip playing on roll over or even a roll-out option, you would need AS 3.0. Well open up a new flash file and make sure you use the ActionScript 3.0 file type.

GETTING TO ACTION PANEL:

So lets get started: if you havent ever used AS 3.0 before you prob dont even know how to input code. Well all you need to do is add a new layer in you main timeline, name it "actions", and on the first keyframe press f9 (MAC option + 9) and you actions panel should come up. Close out of that for know and lets design the button.

BUTTON CREATION:

Design a button in a "stand alone" state. This means when nothing is happening to it. What were going to create is a button that is slightly transparent ("alpha") and then "tweens" to 100% visible when rolled-Over and then tweens back to slightly transparent again when rolled-out all using AS 3.0. So take a few min. to create a button and put it on your stage in a layer called "Button."

CONVERT TO SYMBOL:

You now want to take what you created and convert it to a symbol. Right click your button and click "convert to smybol" now your first intention is going to be to convert to a button but your going to want to convert it to a movie clip. Name it Button and click OK. IMPORTANT STEP!!!!!! GIVE IT A INSTANCE NAME!! This will allow you to use it in AS 3.0. To do this single click your button(which is now a movie clip :-P) and in your property panel you should see an instance name input box. Type in there button_mc and press ENTER. You button can now be used in AS 3.0

SCRIPTING:

Its time to script! ok open up your actions panel (if you dont know how to do this refer to the beginning of this article) and you should see nothing there. copy and paste the following:

//imports everything you need

import fl.transitions.Tween;

import fl.transitions.easing.*;

//default value

button_mc.alpha = .7;

//Event Listeners

button_mc.addEventListener(MouseEvent.ROLL_OVER, buttonOver);

button_mc.addEventListener(MouseEvent.ROLL_OUT, buttonOut);

//functions

function buttonOver(e:MouseEvent):void

{

new Tween(button_mc,"alpha", Strong.easeOut, .7, 1, 24, false);

}

function buttonOut(e:MouseEvent):void

{

new Tween(button_mc,"alpha", Strong.easeOut, e.currentTarget.alpha, .7, 24, false);

}

Now you might be pulling you hair out looking at this but maybe not. If not no need to read on lol. But if you are this is the explaination of the code.

//imports everything you need

import fl.transitions.Tween;

import fl.transitions.easing.*;

simply this tells flash to import these functions. this allows you to ease things in and out and to tween your movie clips.

//default value

button_mc.alpha = .7;

We want your button to start automatically slightly transparent so when its open this code allows that to happen.

//Event Listeners

button_mc.addEventListener(MouseEvent.ROLL_OVER, buttonOver);

button_mc.addEventListener(MouseEvent.ROLL_OUT, buttonOut);

Event Listeners are important in AS 3.0. It basically does what its called.....listens for something. Basically the setup is this :

InstanceNameOfWhatYourEffecting.addEventListener(WhatKindOfEVENT.TheAction, FunctionName);

in the example above were saying listen for a MouseEvent that is Rolling over button_mc. if that happens execute function buttonOver.

//functions

function buttonOver(e:MouseEvent):void

{

new Tween(button_mc,"alpha", Strong.easeOut, .7, 1, 24, false);

}


function buttonOut(e:MouseEvent):void

{

new Tween(button_mc,"alpha", Strong.easeOut, e.currentTarget.alpha, .7, 24, false);

}

functions are the guts of the code. this says what to do when "something" happens. now lets break it up.

function buttonOver(e:MouseEvent):void

this is naming the function buttonOut. also it stores the MouseEvent into a variable e and void means that it returns no data (i.e numbers or strings). Anything you want the function to do goes between the { }.

new Tween(button_mc,"alpha", Strong.easeOut, .7, 1, 24, false);

this is the tween your button is doing. basically your makeing a new tween and this is the setup of it:

new Tween(WhatsBeingEffected."PropertyBeEffected",HowYouWantTweenToLook,StartValue, EndValue,TimeItTakesToTween,false = use keyframes for time true = use seconds for time);

the only other part needing explaining is the e.currentTarget.alpha. This says that the target making the function happen alpha is now the new start position. We do this because we dont want a "snap" effect. If we put 1 there then if the user rolled over before the tween was done, the alpha would jump to 100% alpha and tween back down. We dont want that so we take the curret alpha as the new start position so no jump happens.

And thats about it. test the movie. if your having any trouble at all please post a comment and ill try to help. This is a bit tough i know at first especially learning through reading but im here to answer any questions. :-)

Next Time we'll be discussing FlashVars (Pulling variables from HTML to use in actionscript ;-))

hope you enjoyed,

Eric Hoanshelt

Saturday, April 26, 2008

Loops!!!!!

Program is being programed in Visual Basic


Loops can be useful in many ways. Anything you can think of that you need some statement repeated can be used with loops. The two im going to discuss are Do while and Do until loops. Once you understand one of them you will be able to understand the other because there are practically the samething with one minor difference which will be discussed later. So lets get started with the Do while loops.

First, lets get a idea of a program this can be used for. We will use the exmaple of the Sum of all number. An example of this would be the sum of all number of 10 would be 10+9+8.......+1. So lets get to the program.

You will need the following:
One static label - a label that does not change (Change the text to Sum of Number)

One dynamic label - a label that will be changing (Leave this one blank cause this will be where the answer pops up and name it lblanswer)

One Textbox - name it txtnumber

Three buttons - A calculate button (btncalc) A clear button (btnclear) and a exit button (btnexit)

For the sake of keeping this tutorial simple i will not be adding messages boxes to the exit buttons or anything really.

So now you have you buttons, textbox, and labels ready lets get to the code.

We will start with the exit button.

Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
End
End Sub


This should be good enough without any explanation.

Now we will do the clear button.
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtNumber.Clear()
lblanswer.Text = ""
txtNumber.Focus()
End Sub

The .clear() function clears the variable you set before the function. With the labels the .clear() will not work so we set set it back to an empty string. The .focus() will but the "focus" or the variable with be useable when you click the button. so basically the code above will clear the answer, the textbox with the number and automatically be ready for a new input.

Now the actually loops that you have been waiting for!!!!

Private Sub btncalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalc.Click
Dim counter As Integer
Dim number As Integer
Dim number2 As Integer
Dim result As Integer

counter = 1

number = txtNumber.Text

Do While counter <= number
counter += 1
number2 = number - 1
result = number + number2
Loop
lblanswer.Text = result
End Sub
End Class

The loop actually does the samething over and over while minusing one to make the sum of all numbers, then displays the final result in lblanswer.text.

I used do while but if you wanted to use the Do until you would write DO Until counter = number. You should be able to read the difference on Do whiles and Do until......its common english. Have Fun!

Tuesday, January 22, 2008

What if?

What if is a simple statement that can be followed by anything. What if the world was flat? What if my hair was black? What if "if" can be used in programming? Well it can! The If........then statement can be used to tell a program to do something if a condition is met or not met. This is the basic format of the If........then statement:

If [condition] then
[do this]
endif

Its better explained like:
If [it is cold outside] then
[put on a sweater]
end if

Between the if........then there should be something there that the computer can work out. An operator like + - / * ^ = > < are the most commonly used. Example of this will be

If x + y = 10 then
label should show 10
end if

Where x represents a dimension you set and y represents a dimension you set. Label represents a "label" you put in the form.( make sure to give the label a unique name) For the above code it would look something like this.

Dim number1 as integer
Dim number2 as integer

'Set variables
number1 = [Val(txtfirstnumber)] <-------we will let this be x

number2 = [Val(txtsecondnumber)]<------we will let this be y

'the if statements

if number1 + number 2 = 10 then
lblanswer.text = "Those two numbers equal 10"
endif

There you have it.

Next week i will go over If.........then..........else!


Reminder: this is for a class and if there is something i left out, we already covered it in class. So if you are just surfing the web and have a Q. about something i left out just post a comment.

Saturday, January 12, 2008

Only 10 types of people will understand this!

Binary……….the language that computers speak. What is this binary language? Its is a language that computers speak that consist of only off and on switches, off being represented by 0’s and on represented by 1’s. A system bases on these 2 numbers is call a base2 system. Well lets get started with the first lesson: converting decimals to binary.

A decimal is basically any number, so we are going to start with the number 20. How are we going to make the decimal 20 into a base2 system so it can be read in binary. We do this by dividing the decimal by the number 2 first. We come out with an answer with no remander. If this is the case that will represent a 0.

Now we have the number 10 from the previous problem(20/2=10). We now do the samething with 10. We divide it by 2 and again we come up with a number that doesn’t have a remander. Again this will be a 0. Now we have 5. Unlike the other numbers, this is odd. So we will be left with a remander of 1. You guessed it, this will give us a 1 in the binary code. With the whole number left (2) that is the number we continue with. 2/2 is 1 with no remander and so that is a 1 also in binary. Now we are left with the last number which is 1 and that will be our final problem which leaves us with out final 1.

Lets review the binary we have for 20:

20=00101

Now read the binary backwards and you get 10100. That is the binary for the decimal 20.

Now lets go backwards. How will we get 20 out of 10100. Well, because we are in a base2 system, the numbers 1 and 0 are exponetially increasing by 2 (ex. 1,2,4,8,16,32). So what you do is make a chart as the one below.

__16(2^4)__|__8(2^3)__|__4(2^2)__|__2(2^1)__|_1(2^0)_

Now plug in you binary to the chart above so that each digit has its own place value like the one below:

__16(2^4)__|__8(2^3)__|__4(2^2)__|__2(2^1)__|_1(2^0)_

1 0 1 0 0

Now add the values together that has a 1 in the place value: 16+4=20

Thats how you convert binary to decimal.

Welcome

This blog is dedicated to help you learn technical things!