Thursday, October 8, 2009

Actionscript(AS3 and AS2) Tips

AS2 Best practices

OnRelease in Event in AS2 and AS3
hitTest Method of movieclip



Flash debug player installation
http://blog.hydrotik.com/2007/10/01/as3-useful-little-things/

Conventions: http://opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions

usefull downloads: http://www.senocular.com/flash/source.php
Good Tutorials:http://www.gotoandlearn.com/
Vector,Metrics 3D classes in CS4?  used in  globe:


preloader


disable right click with javascript and AS3
Code: http://www.uza.lt/blog/2007/08/solved-right-click-in-as3/






Adjust on resize

stage.addEventListener(Event.RESIZE, onResize, false, 0, true);

//assuming that eh main movieclip is having 3 childs
1.header
2.footer
3.view: main content area which holds all other children in the page


public function resize(e:Event = null):void {
  if (view.numChildren > 0) {
  Page(view.getChildAt(0)).resize();
  }
  header.resize();
  footer.resize();
  footer.y = stage.stageHeight - footer.defaultHeight + 1;
  }








loading and resizing display area with javascript and using asual classes


<script src="js/swfobject.js" type="text/javascript">

</script>

<script src="js/swfaddress.js" type="text/javascript">

</script>

<script type="text/javascript">

var size = getViewportSize();

function getViewportSize()

{

var size = [0, 0];

if (typeof window.innerWidth != "undefined") {

size = [window.innerWidth, window.innerHeight];

}

else if (typeof document.documentElement != "undefined" &amp;&amp; typeof document.documentElement.clientWidth != "undefined" &amp;&amp; document.documentElement.clientWidth != 0) {

size = [document.documentElement.clientWidth, document.documentElement.clientHeight];

}

else {

size = [document.getElementsByTagName("body")[0].clientWidth, document.getElementsByTagName("body")[0].clientHeight];

}

return size;

}

function createFullBrowserFlash()

{

// swfobject.createCSS("window", "overflow:auto;");

swfobject.createCSS("html", "height:100%; margin:0; padding:0;");

swfobject.createCSS("body", "height:100%; margin:0; padding:0;");

swfobject.createCSS("#flash", "margin:0; width:100%; height:100%; min-width:1024px; min-height:786px; display:block;");

window.onresize = function() {

var el = document.getElementById("flash");

var size = getViewportSize();

el.style.width = size[0] < 986 ? "1024px" : "100%";

el.style.height = size[1] < 800 ? "786px" : "100%";

};

window.onresize();

}

function setHeight( h )

{

if ( h < size[1] ) h = "100%";

var el = document.getElementById("flash");

if ( h != "100%" ) el.style.height = h < 786 ? "786px" : h + "px";

else el.style.height = "100%";

}

//bgcolor: "#513e2c",


var params = {

quality: "high",

scale: "noscale",

wmode: "window",

allowscriptaccess: "always",

bgcolor: "#513e2c",

allowFullScreen: "true"

};

var flashvars = {

controllerPath:"swf/THLM-THLM.swf",

totalExternalBytes:"7278224"//"3911744"

};

var attributes = {id:"flash"};

swfobject.embedSWF("Preloader.swf", "flashcontent", "400", "400", "10.0.0", "expressInstall.swf", flashvars, params, attributes);

if (swfobject.hasFlashPlayerVersion("10.0.0")) {

swfobject.addDomLoadEvent( createFullBrowserFlash );

}

</script>








asual Deeplinking with.htaccess,setting page title,changing url in addressbar thereby enabling SEF pages in flash sites


changing url path in address bar
SWFAddress.onChange = goto;///this is setting event listener,inside go to function we must write code to load the xhtml file in the relative url set as follows

SWFAddress.setvalue('relative url');


if it is an absolute url(starting with http)write it as following in goto function



if(linkToGo.substr(0,5) == "/http")

{

GlobalVars.getURLFromMain(new URLRequest(SWFAddress.getValue()));

return;

}

Textfield cursor and string insetrtion
       first stage.focus = activeTextRef;    


       private function insertCharAtCursor(stringToInsert)
        {
            var activeTextRef = _base.txtEmail;
            var cusrsorPos = activeTextRef.caretIndex;
            //trace("cusrsorPos = "+ cusrsorPos);
            var mainString:String = activeTextRef.text;
            var fstring = mainString.slice(0,cusrsorPos);
            var lstring = mainString.slice(cusrsorPos,mainString.length);  
            if(stringToInsert == 'backSpace')
            {
                if(cusrsorPos >0)
                {
                    fstring = mainString.slice(0,cusrsorPos - 1);
                    if(cusrsorPos < mainString.length)
                    {
                        lstring = mainString.slice(cusrsorPos,mainString.length);  
                    }
                    else
                    {
                        lstring = '';
                    }
                }
                stringToInsert = '';
            }
            //activeTextRef.text += stringToInsert;
            activeTextRef.text = fstring + stringToInsert + lstring
            /*if(!_base.mouseClickedOnTextbox)
            {  
              
                activeTextRef.setSelection(activeTextRef.text.length,activeTextRef.text.length);
            }
            else*/
            {
                var midstring:String = fstring + stringToInsert
                var newCaretPos = midstring.length;
                activeTextRef.setSelection(newCaretPos,newCaretPos);
            }
        }


Masking Options

gradient maskwith alpha channel? <a href="http://www.senocular.com/flash/source.php?id=0.180">http://www.senocular.com/flash/source.php?id=0.180</a>









Options Presentation

Menu

Accordion

Slider(easing scrollbar)

Context menu




Skinning

Skinning Controls

Text format

Applying CSS in textfields






Transitions

"Masking Options

(gradient,solid)"

Slideshow

flip sample1 ,

carousal: gotoandlearn

Gallery

accordion

Audio Player  :Sound Object  , Sound channel ,load,close,play,stop

Video Player




Movement

Circlular(with sin and cos)

3d movement(Cube,papervision)

Sine wave type

Zigzag

Drawing:


Actionscript movieclip.transform.matrix

http://www.kirupa.com/developer/actionscript/3dindex.htm
Simple 3D Drawing in Flash CS3
3dpicturebox.fla





Frontend (inbrowser)Communication

Js communication

Flash to flash communication in same browser page




Flash to Backend Communication

"XML handling"

loadvars

JSON

AMFPHP




FMS

basic functions

call function in serer from client

call function in client from serer

checking bandwidth

shared object

User interaction(chat)

whiteboard

Online teaching




Extending Flash

Creating And Deploying Component

Creating And Deploying flash Extensions

changin color of movieclips
AS2
var c:Color = new Color(box_mc);
c.setRGB(Math.random() * 0xFFFFFF);

AS3
var c:ColorTransform = new ColorTransform();
c.color = (Math.random() * 0xFFFFFF);
box_mc.transform.colorTransform = c;

No comments:

Post a Comment