Tag Archive for external

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

AS3 Loading and Using an External CSS File

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.text.StyleSheet;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;

	public class CSSFormattingExample extends Sprite {
		var loader:URLLoader;
		var field:TextField;
		var exampleText:String = "<h1>This is a headline</h1>" +
		"<p>This is a line of text. <span class='bluetext'>" +
		"This line of text is colored blue.</span></p>";

		public function CSSFormattingExample():void {
			field = new TextField();
			field.width=300;
			field.autoSize=TextFieldAutoSize.LEFT;
			field.wordWrap=true;
			addChild(field);

			var req:URLRequest=new URLRequest("example.css");

			loader = new URLLoader();
			loader.addEventListener(Event.COMPLETE, onCSSFileLoaded);
			loader.load(req);
		}

		public function onCSSFileLoaded(event:Event):void {
			var sheet:StyleSheet = new StyleSheet();
			sheet.parseCSS(loader.data);
			field.styleSheet=sheet;
			field.htmlText=exampleText;
		}
	}
}


// THE 'example.css' FILE SHOULD LOOK LIKE THIS ...
//p {
//	font-family: Times New Roman, Times, _serif;
//	font-size: 14;
//}
//
//h1 {
//	font-family: Arial, Helvetica, _sans;
//	font-size: 20;
//	font-weight: bold;
//}
//
//.bluetext {
//	color: #0000CC;
//}

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

automatically send external links to new window with mootools

window.addEvent('domready', function() {
    // modified from <a href="http://joesong.com/2009/11/external-links-in-new-window-passive-and-with-mootools/" >http://joesong.com/2009/11/external-links-in-new-window-passive-and-with-mootools/</a> 
    // to avoid using the 'target' attribute, which is not part of xhtml 1.0 strict
    var currentDomain = window.location.host;
    $(document.body).addEvent('click', function(evt) {
	var target = $(evt.target);
	if (target.get('tag') !== 'a') {
	    target = target.getParent();
	}

	if (target && target.get('tag') === 'a' && target.get('href').test('http') && !target.get('href').test(currentDomain)) {
	    window.open(target.get('href'), '_blank');
	    return false;
	}
    });
});

source

link linking to external css file

<link rel="stylesheet" type="text/css" href="test.css" />

@import url("base.css");

source

jQuery External Link Snippet for XHTML Strict 1.0

<script type="text/javascript">
	$(document).ready(function(){
		$('a[rel="external"]').click(function(){ // When a link with rel="external"is clicked ...
			window.open( $(this).attr('href') ); // ... open a new window using the link's href attribute ...
					
			return false; // ... and prevent the default browser functionality (opening the link in the same window).
		})
	})
</script>

source

ADD TARGET BLANK TO ALL EXTERNAL LINKS

$("a[href^=<a href="http://]").not("a[href^=http://www.yourdomain]").attr("target"," >http://]").not("a[href^=http://www.yourdomain]").attr("target",</a> "blank");
$("a[href^=<a href="http://]").not("a[href^=http://www.yourdomain]").attr("rel"," >http://]").not("a[href^=http://www.yourdomain]").attr("rel",</a> "external");

source

Embedded Image in Flash

package {

	import flash.display.Sprite;
	import flash.display.BitmapData;
	import flash.display.Bitmap;
	
	class EmbeddedImageExample extends Sprite
	{
		[Embed(source='photo.png')]
		private var photoClass:Class;
		private var photo:Bitmap;

		function EmbeddedImageExample()
		{
			photo = new MyPhoto();
			var bmp:BitmapData = photo.bitmapData;
		}
	}
}

source

Leggere una variabile esterna in AS3

var mia_variabile=loaderInfo.parameters['var']!=undefined?loaderInfo.parameters['var']:"vuota"; 

-----------------------
so.addParam("FlashVars", "var=test");

source