right_side
The IF Structure

The if structure is used when you want to perform a specific/indicated action. It is activated when the condition becomes true. For example you have assigned a value to variable x=0 and you use if strutcutre like this

if(x==10) {
    perform any action;
}

in this case this statement will be activated when the value of x becomes 10. If the value of x becomes 10 it means the conidtion is true. Basically we use it for comparing two or more statements.

How to use IF Structure
——————————-
It is very simple to use, for example you are moving a sprite on x-axis and you are continously increasing its _X position. e.g the initial _X of your sprite was 0 and you want that when it reaches 200 then you want your sprite go back on _x=0 and start. What you will do is

Example 1
————-
1. Make a rectangle and convert it to sprite. Rename “sprite” as “bar”. From transform tab place it on X=0
2. On the frame number 1 paste this code

 

CODE
onEnterFrame() {
   bar._X+=1;
   if(bar._X==100){
     bar._X=0; 
   }
}


Now in this line bar._X+=1; we are only changing the position continously but in code

if(bar._X==100){
   bar._X=0;
}

we are comparing the X with 100, here we have stated that if X reaches 100 then again assign a new value to X which is 0.

else-if Structure
The [b]else
is used when you also want to perform an action when the statement is flase. For example in
the above Example we have only used if structure. Ok now I will make the same example using if else

Example 2
————-
1. Make a rectangle and convert to sprite. Rename “sprite” as “bar”. Place it on X=0
2. On the frame number 1 paste this code

onEnterFrame() {
    if(bar._X==100){
       bar._X=0;
    } else bar._X+=1;
}

Now this example will also perform the same action as Example 1. But the only difference is that we
have used if else. Concentrate on the code, you have seen when the movie starts the bar._x=0 because we have palced it at 0, it means the if is activated.

This is how if and if else statements works. You can make as many comparisons you want. In the above example 2 we have made only one if structure

What is a typical else if
The word Typical in this case, is in the sense, you might have seen codes like this

CODE
on (release) {

   if(inputVar==”Ali”){
       dynVar=”Administrator”;
   } else if(inputVar==”Charly”){
       dynVar=”Moderator”;
   } else if(inputVar==”rob88wells”){
       dynVar=”Co-Admin”;
   } else if(inputVar==”johno”){
       dynVar=”Member”;
   } else dynVar=”Guest”;

}


In the above code you have made one input box and its variable name is inputVar and one dynamic text box and its variable name is dynVar. Made on buttons and on its action we used the aboce code. Now this code will check the string (means the text you write) if it is “Ali”  then in Dynamic TEXT box (dynVar) it will display “Administrator”, the same if the string is “Charly” it will display “Moderator”. After comparing all else if structure, if there are no matches then it will display “Guest” in the dynamic text box.

So now you can make and use else if and simple if structures.
Ok - here is the list of operators you will be using in these structures.

Operator Description
< relational less than
<= relational less than or equal to
> relational greater than
>= relational greter than or equal to
= assignment operator (for assignin any value to any variable/expression)
== is equal to
!= is not equal to

&& logial AND
|| logical OR

some other operator which may be used in other codings.
+= addition asignment
-= subtraction asignment
*= multiplication asignment
+= division asignment

I think its enough to understand for an intermediate or basic level user.
If you have any further questions, feel free to ask.

What are object properties ?

Everything you design in Swishmax is an object, like SPRITE is an object, the TEXT you write is also is TEXT OBJECT. Shapes are Shape Objects. We can easily set/change properties. And assign new values to any object’s properties.

You can create Shape Objects using the following drawing tools:

Line
Pencil
Bezier
Rectangle
Ellipse
AutoShapes.

OBJECT PROPERTIES

  • _X     =  for X-axis of an object
  • _Y     =  for Y-axis of an object
  • _xscale     =  for strecthing abject on x-axis   <—>
  • _yscale     =  for strecthing abject on y-axis (top to bottom)
  • _alpha     =  for objects alpha value (transparency)
  • _rotation     =  rotating object on x-axis
  • _visible     =  this is a boolean expression (true or false)
  • _height     =  height of an object
  • _width     =  width of an object
  • _name     =  return name an object
DESCRIPTION

Assigning Values to Object Properties
NOTE : when you make an object dont forget to give object name and CHECK the button target.

It is not much difficult to understand the properties of objects. You can easily assign new values or retrieve the actual values by different methods. Its really easy to assign new values to each property e.g you have a SHAPE Object, and its name is myshape now you will assign values like this


onFrame (1) {
   myshape._X=200;
   myshape._y=100;
   myshape._height=10;
   myshape._width=10;
   myshape._xscale=200;
   myshape._yscale=400;
   myshape._alpha=100;
   myshape._rotation=0;
   myshape._visible=true;
}

In my example I made a rectangle of widht=1 and height=1 and placed it on x=0 and y=0. When I will play my Movie, all the values will be changed automatically. If you will set myshape._visible=false; the object will be hidden.

Retrieving actual property values of Object

This is also not difficult to understand, what you have to do is simply make a variable and assign it the object property variable, for example you want to get the value of Shape object myshape and save it to any other variable newX, then simple do it like this

newX=myshape._X;

now the variable newX contains the value X-axis of myshape object. I thinks now it will be clear to you, what are object properties and how to handle them. It may help the beginners to SWiSHScript.

Posted on 20 Nov 2008 In: Web Tutorials

Basic Understanding of Variables

What is variable.

A variable is a value that is not constant. This value is changed conditionally. For example weather is a variable, it is not same always. Now in SWiSHScript, for example “X” is a variable and its value is
assigned x=10; in the beginning of Movie, but we want to change its value at runtime (means you can change value while your SWF file is playing), so we will simply assign a new value to “X” as x=20; at any frame.

Why we use variables?

Variables are used in many different ways to perform any specific task. For example for getting/changing X,Y postions of sprite, for changing alpha, width etc. You can direclty assign a new value to the object property (_width, _alpha, _X, _Y etc). Variables are also used to send/retierve data to/from PHP,ASP, JScript etc.

Here is an Example

For example you have a sprite named as circle and you want to know its X position (what is the exact locaion of x where circle sprite is located). Also check the provided example.

[swf=200x103]http://www.swish-db.com/Board/attach/smax/drgcir.swf[/swf]

On the very first frame of movie we have assigned a Static value to variable
vartext

 

CODE
onFrame (1) {
   vartext=43;
}


This variable is assigned to display its value 43 in dynamic textbox.
Now see the Script on shape circle

CODE
on (press) {
   startDragUnlocked();
}

on (release) {
   stopDrag();
   _root.vartext=_root.circle._X;
}


here we have assigned a dynamic value to a variable vartext, which is not static,
it changes when you drop cirle to any other point.

Download Example

In the above explanantion you have learned how to assign a vlaue to a variable. For more details about Data Types of variables please read the following tutorial. Data type is basically the characteristic of Variables (what kind of data they are supposed to handle i.e numeric, string, boolean).

http://www.swish-db.com/phpBB2/viewtopic.php?t=5469

I assume that you have read the tutorial for loading external from a text file. If not then read the following tutorial first.

It is not much complicated, just perform the following steps and your
scroll bar is ready.

Follow The steps..
——————-
1. In above tutorial the Dynamic text box in Single Line, so first
change it to Multi Line

2. In TEXT file put as many lines as you want. remember if the lines will
not exceed the size of TEXT box, the buttons will not work, I mean you
must put about 20 lines data in TEXT files.

3. In my text file I have this text (From Daryl Signature )

QUOTE

When children have to play inside so they don’t disappear, private eyes solve marriage lies cause we dont talk for years, and football teams are kissing queens and losing sight of having dreams - In a world where all we want is only what we want untill it’s ours, I’m calling all angels.

4. Now make two buttons, one with arrow up and one with arrow down.
In Webdings Font 5 is arrow up and 6 is arrow down, its upto you.

5. Now rightclick Arrow Up button and in its Actions, paste the following code.

CODE
on (release) {
    data.scroll–;
}

DESCRIPTION

Now lets see this line data.scroll–.
As you know data is our varialble which we are using to load external text.
So its easy to understand what is going on here. Secondly if your Dynamic Text Box
is in any other movie for example you MovieClip() name is news then you will use it
like this news.data.scroll–.

6. Now on Arrow Down button, in its Action, paste the following code.

CODE
on (release) {
   data.scroll++;
}

thats it. I hope its very easy to understand, if you are facing any problems please
feel free to ask questions.

Download Example File