Tag Archive for load

AS3 Load External Text File

package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	public class Main extends MovieClip
	{
		private var _txtFileToLoad:String = "myTextFile.txt";
		private var _txtLoader:URLLoader;
		private var _loadedTxt:String;
		

		public function Main():void
		{
			loadExternalTxtFile();
		}
		
		private function loadExternalTxtFile():void
		{
			_txtLoader = new URLLoader();
			_txtLoader.addEventListener(Event.COMPLETE, onTxtLoader_COMPLETE);
			_txtLoader.addEventListener(IOErrorEvent.IO_ERROR, onTxtLoader_IO_ERROR);
			_txtLoader.load(new URLRequest(_txtFileToLoad));
		}
		
		private function onTxtLoader_COMPLETE(event:Event):void {
			_txtLoader.removeEventListener(Event.COMPLETE, onTxtLoader_COMPLETE);
			_txtLoader.removeEventListener(IOErrorEvent.IO_ERROR, onTxtLoader_IO_ERROR);
			_loadedTxt = String(event.target.data);
			trace(_loadedTxt);
		}
		
		private function onTxtLoader_IO_ERROR(event:Event):void {
			_txtLoader.removeEventListener(Event.COMPLETE, onTxtLoader_COMPLETE);
			_txtLoader.removeEventListener(IOErrorEvent.IO_ERROR, onTxtLoader_IO_ERROR);
			trace(event.target.text);
		}

	}
}

source

jQuery dynamic loader – load jquery using pure js javascript if jQ is undefined or does not exist

// jQuery dynamic loader - load jQuery using pure javascript js
// if jQuery is undefined or does not exist, then load it

if ( !window.jQuery ) {
	var jqscript = document.createElement('script');
	jqscript.setAttribute("type", "text/javascript");
	jqscript.setAttribute("src", "<a href="http://code.jquery.com/jquery.min.js");" >http://code.jquery.com/jquery.min.js");</a>
	document.getElementsByTagName("head")[0].appendChild(jqscript);
};

source

js jQueryLoader – check if $ is undefined, then load jquery with pure javascript if needed

/* I used to use (!$) or ($ == undefined) but that doesn't work sucka! */

if (!window.jQuery) {
	var jqscript = document.createElement('script');
	jqscript.setAttribute("type", "text/javascript");
	jqscript.setAttribute("src", "<a href="http://code.jquery.com/jquery.min.js");" >http://code.jquery.com/jquery.min.js");</a>
	document.getElementsByTagName("head")[0].appendChild(jqscript);
};

source

HTML5 Beginers Layout With Google Ajax Load

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>HTML5 Beginers Layout</title>
<script type="text/javascript" src="<a href="http://www.google.com/jsapi"></script>" >http://www.google.com/jsapi"></script></a>
<script type="text/javascript">
google.load("jquery", "1.4.2");
google.load("jqueryui", "1.8.2");
</script>
<!--[if lt IE 9]>
<script type="text/javascript" src="<a href="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>" >http://html5shiv.googlecode.com/svn/trunk/html5.js"></script></a>
<![endif]-->
</head>
<body>
    <header>
        <hgroup>
            <h1>Page Header</h1>
            <h2>Description May Go Here</h2>
        </hgroup>
    </header>

    <nav>
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>

    <article>
        <header>
            <h1>Article Header</h1>
            <time datetime="2010-05-05" pubdate>June 25th 2010</time>
        </header>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
        <section>
            <header>
                <h1>Section Header</h1>
            </header>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
            <footer>
                <p>Section Footer</p>
            </footer>
        </section>
        <footer>
            Article Footer
        </footer>
    </article>

    <aside>
        <header>
            <h1>Siderbar Header</h1>
        </header>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </aside>

    <footer>
        Page Footer
    </footer>

</body>
</html>

source

HTML5 Basic Template (w /Google Load)

<!DOCTYPE html>
<html lang="en">
<head>
<title>Webpage Title</title>
<meta charset="utf-8" />
<script src="<a href="http://www.google.com/jsapi"></script>" >http://www.google.com/jsapi"></script></a>
<!--[if lt IE 9]>
<script src="<a href="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>" >http://html5shiv.googlecode.com/svn/trunk/html5.js"></script></a>
<![endif]-->
<script>
  google.load("jquery", "1.4.2");
</script>
</head>
<body>

</body>
</html>

source

AS3 Loading and Playing an External MP3 File

import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;

var snd:Sound = new Sound();
var channel:SoundChannel = new SoundChannel();
snd.load(new URLRequest("song.mp3"));
snd.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
function onComplete(evt:Event):void {
	channel = snd.play();
}

source

Random HTML content on load

<SCRIPT LANGUAGE="Javascript">
                    function banner() { } ; b = new banner() ; n = 0
                    b[n++]= "<IMG name=randimg SRC='images/video_stills/01.jpg' border='0' ALT=''>"
                    b[n++]= "<IMG name=randimg SRC='images/video_stills/14.jpg' border='0' ALT=''>"
                    b[n++]= "<IMG name=randimg SRC='images/video_stills/04.jpg' border='0' ALT=''>"
                    b[n++]= "<IMG name=randimg SRC='images/video_stills/02.jpg' border='0' ALT=''>"
                    b[n++]= "<IMG name=randimg SRC='images/video_stills/10.jpg' border='0' ALT=''>"
                    b[n++]= "<IMG name=randimg SRC='images/video_stills/05.jpg' border='0' ALT=''>"
                    i=Math.floor(Math.random() * n) ;
                    document.write( b[i] )
                </SCRIPT>

source

FLASH – load image loadClip

var imageListener:Object = new Object();
imageListener.onLoadInit = function() {
var aimageTween:Tween = new Tween(holder_mc, "_alpha", Regular.easeOut, 0, 100, 1, true);
}
var imageLoader:MovieClipLoader = new MovieClipLoader();
imageLoader.addListener(imageListener);
imageLoader.loadClip("/photos/filename.png", holder_mc);

source

Server Load Emailer

#!/bin/sh

# Start clean!
if [ -f /tmp/emailTMP ]; then
rm -rf /tmp/emailTMP
fi

if [ -f /tmp/procTMP ]; then
rm -rf /tmp/procTMP
fi

if [ -f /tmp/sendmailTMP ]; then
rm -rf /tmp/sendmailTMP
fi

# Init variables
eMail="email@somewhere.com"
serverLoadLog=/var/log/custom/serverLoad.log
procTMP="/tmp/procTMP"
memLimit=50
memWarning=25
memTripped=FALSE
cpuLimit=99
cpuWarning=50
cpuTripped=FALSE

emailReport() {
if [ -f /tmp/emailTMP ]; then
echo "Subject: cshaiku.com Server Load Status"  > /tmp/sendmailTMP
cat /tmp/emailTMP      >> /tmp/sendmailTMP
printf "
$emailDate"  >> /tmp/sendmailTMP
echo "--[`date`]--"    >> $serverLoadLog
cat /tmp/sendmailTMP   >> $serverLoadLog
/usr/sbin/sendmail -v "$to" < /tmp/sendmailTMP > /dev/null
fi
}

checkMemoryUsage() {
printf "
+----------+--------------+------+======+----------------------------------+" >> $serverLoadLog
printf "
|      PID |         User |  CPU |  MEM |                          Command |" >> $serverLoadLog
printf "
+----------+--------------+------+======+----------------------------------|" >> $serverLoadLog
ps -eo pmem,pcpu,user,pid,comm | sort -rn | head -10 > $procTMP
while read pmem pcpu user pid command
do
declare -i pmemINT=`echo $pmem | awk '{printf "%.0f",$1}'`
if [ $pmemINT -gt $memLimit ]; then
set memTripped=TRUE
kill $pid
printf "

Killed pid $pid		user: $user	cpu: $pcpu	mem: $pmem	Command: $command
" >> $serverLoadLog
printf "

Killed pid $pid		user: $user	cpu: $pcpu	mem: $pmem	Command: $command
" >> /tmp/emailTMP
elif [ $pmemINT -gt $memWarning ]; then
set memTripped=TRUE
printf "

pid $pid		user: $user	cpu: $pcpu	mem: $pmem	ommand: $command
" >> $serverLoadLog
printf "

pid $pid		user: $user	cpu: $pcpu	mem: $pmem	ommand: $command
" >> /tmp/emailTMP
else
if [ $pid != "PID" ]; then
printf "
|%9s | %12s | %4s | %4s | %32s |" $pid $user $pcpu $pmem $command >> $serverLoadLog
fi
fi

done < $procTMP

if [ $memTripped = TRUE ]; then
printf "
The following commands have surpassed the Memory Usage threshold (%s)." "$memWarning%" >> /tmp/emailTMP
fi
}

checkCPUUsage() {
printf "
+----------+--------------+======+------+----------------------------------+" >> $serverLoadLog
printf "
|      PID |         User |  CPU |  MEM |                          Command |" >> $serverLoadLog
printf "
+----------+--------------+======+------+----------------------------------|" >> $serverLoadLog
ps -eo pcpu,pmem,user,pid,comm | sort -rn | head -10 > $procTMP
while read pcpu pmem user pid command
do
declare -i pcpuINT=`echo $pcpu | awk '{printf "%.0f",$1}'`
if [ "$pcpuINT" -gt "$cpuLimit" ]; then
set cpuTripped=TRUE
kill $pid
printf "

Killed pid $pid !		user: $user	cpu: $pcpu	mem: $pmem	Command: $command
" >> $serverLoadLog
printf "

Killed pid $pid !		user: $user	cpu: $pcpu	mem: $pmem	Command: $command
" >> /tmp/emailTMP
elif [ "$pcpuINT" -gt "$cpuWarning" ]; then
set cpuTripped=TRUE
printf "

pid: $pid	user: $user	cpu: $pcpu	mem: $pmem	Command: $command
" >> $serverLoadLog
printf "

pid: $pid	user: $user	cpu: $pcpu	mem: $pmem	Command: $command
" >> /tmp/emailTMP
else
if [ $pid != "PID" ]; then
printf "
|%9s | %12s | %4s | %4s | %32s |" $pid $user $pcpu $pmem $command >> $serverLoadLog
fi
fi

done < $procTMP

if [ $cpuTripped = TRUE ]; then
printf "
The following commands have surpassed the CPU Usage threshold (%s)." "$cpuWarning%" >> /tmp/emailTMP
fi
}

# Main Loop
checkCPUUsage
checkMemoryUsage
emailReport

# End Clean!
rm -rf /tmp/emailTMP
rm -rf /tmp/sendmailTMP
rm -rf /tmp/procTMP

source