Difference between revisions of "Actionscript"

From Wikicliki
Jump to: navigation, search
Line 1: Line 1:
actionscript, that infuriatingly intractable marshmellow fluff...
+
== Basics Operators, Conditionals, Codehinting ==
so far i have only understood the most basic of concepts, but now i will try to learn it well.
 
  
*[[Actionscript Sandbox]]
+
=== Conditionals ===
*[http://moock.org/lectures/groundUpAS3/ Moock's Actionscript 3.0 from the Ground Up]
 
  
*http://www.kirupa.com/developer/actionscript/spring.htm
+
<code>var message = "yellow";                        // the equal sign assigns values to variables
*http://www.bit-101.com/tutorials/elasticity.html
+
trace ("big " + message + " truck");            // prints "big yellow truck"
 +
if (message == "yellow") {                      // the double equal sign checks to see if variables are equal
 +
trace ("yes, i did say big yellow truck.");    // prints "yes, i did say big yellow truck"
 +
trace (typeof message);                        // prints "string"
 +
var x = a;                                      // prints "number"
 +
trace (typeof a)
 +
}</code>
  
  
== alpha ==
+
== Runtime Environment ==
<pre>
+
=== Detecting player/OS and setting movie dimensions ===
// set movie clip's alpha (transparency) to 50% immediately
 
myMC._alpha = 50%
 
 
 
// set up alphacounter, if alphacounter is undefined then it sets it to 99. otherwise alphacounter is to decrease to 0 and delete itself.
 
myMC.onEnterFrame = function (){
 
this.alphaCount = (this.alphaCount == undefined) ? 99 : --this.alphaCount;
 
this._alpha = this.alphaCount;
 
if (this._alpha <= 0) {
 
delete this.onEnterFrame;
 
}
 
}
 
 
 
// change it to ++ to make it go up
 
</pre>
 
 
 
== Codehinting ==
 
 
 
to keep with good practice you should keep to these common suffixes so that any programmer can read your code easily without finding it utterly incomprehensible.
 
 
 
variables:
 
*must start with letters, underscore or dollarsign.
 
*no hyphens or other punctuation besides the underscore.
 
*cannot start with a number.
 
*are case-insensitive, but keep it constant or you might get confused
 
 
 
*xxx_str  // means the variable contains a string
 
*xxx_arr // means the variable contains an array
 
 
 
*[http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001151.html More about using suffixes to trigger code hints]
 
 
 
== Conditionals ==
 
 
 
<pre>var message = "yellow";
 
trace ("big " + message + " truck");                // prints "big yellow truck"
 
if (message == "yellow") {
 
trace ("yes, i did say big yellow truck.");        // prints "yes, i did say big yellow truck"
 
}</pre>
 
 
 
<pre>= assigning value
 
== comparing values</pre>
 
 
 
== loops ==
 
 
 
<table><tr><td valign=top>this sequence... <pre>trace (101);
 
trace (102);
 
trace (103);
 
trace (104);
 
trace (105);</pre></td>
 
<td valign=top>is equal to:
 
<pre>var x = 101;
 
trace (x);
 
x = x + 1;
 
trace (x);
 
x = x + 1;
 
trace (x);
 
x = x + 1;
 
trace (x);
 
x = x + 1;
 
trace (x);</pre></td>
 
<td valign=top>is also equal to:
 
<pre>var x = 101;
 
while (x <= 105) {    // as long as x is less than 105...
 
trace (x);
 
x = x + 1;          // ...continue to trace x but add one each time
 
}</pre></td>
 
<td valign=top>they all print:
 
<pre>101
 
102
 
103
 
104
 
105</pre></td></tr></table>
 
 
 
== functions ==
 
 
 
sample:
 
 
 
<pre>function area(height, width){
 
return height * width;
 
}
 
area1 = area(10,15);
 
area2 = area(10,20);
 
area3 = area(10,20);
 
</pre>
 
 
 
== event based execution ==
 
 
 
<pre>someObject.onSomeEvent = someFunction;</pre>
 
 
 
for example:
 
<pre>skaGirl.onRelease = dirtyskanking;            // the object named skaGirl will dirtyskank when mouse is released
 
 
 
function dirtyskanking () {
 
this._parent._rotation = 360;                    // defines the rotation of the dirtyskanking.
 
}
 
</pre>
 
 
 
== sample ==
 
 
 
=== quiz ===
 
 
 
<pre>
 
button1.onRelease = function () {        // on pressing button 1
 
this._parent.q1answer = 1;                // assigning 1 to q1 answer
 
this._parent.gotoAndStop("q2")            // after which we go to frame labelled as q2
 
}
 
 
 
if (q1answer == 3) {                      //  if answer was right
 
  totalCorrect = totalCorrect++;          //  increase number of total correct qns by one
 
}
 
</pre>
 
 
 
== confused about root, this, and parent? so am i! ==
 
 
 
this piece of code would work ON a frame on the main stage, one_mc being an object onnit.
 
 
 
<pre>function T1over() {
 
_root.one_mc.gotoAndStop(2);
 
getURL('javascript:modifyT1();');
 
}
 
 
 
_root.one_mc.onRollOver = T1over;</pre>
 
 
 
== actionscript and javascript ==
 
 
 
*[http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15683 flash to/from javascript call]
 
*[http://board.flashkit.com/board/archive/index.php/t-578023.html halp i am so confused]
 
 
 
== tips ==
 
 
 
* use frame labels rather than frame numbers. you could call a starting frame "init".
 
* dont use too many functions
 
 
 
== See Also ==
 
*[http://livedocs.adobe.com/flashlite/2/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000642.html preloader]
 
*[http://www.sephiroth.it/python/sepy.php SEPY actionscript editor]
 
*[http://www.mtasc.org/ Motion-Twin ActionScript 2 Open Source free compiler.]
 
*[http://code.google.com/p/swfobject/ SWFobject]
 
*[http://hosted.zeh.com.br/mctween/index.html MC Tween - Best way to tween]
 
*[http://code.google.com/p/tweener/ Tweener - New way to tween]
 
 
 
*[http://labs.adobe.com/wiki/index.php/ActionScript_3:resources:apis:libraries actionscript apis (youtube, odeo)]
 

Revision as of 09:49, 22 September 2008

Basics Operators, Conditionals, Codehinting

Conditionals

var message = "yellow"; // the equal sign assigns values to variables trace ("big " + message + " truck"); // prints "big yellow truck" if (message == "yellow") { // the double equal sign checks to see if variables are equal trace ("yes, i did say big yellow truck."); // prints "yes, i did say big yellow truck" trace (typeof message); // prints "string" var x = a; // prints "number" trace (typeof a) }


Runtime Environment

Detecting player/OS and setting movie dimensions