Advertising many sites have used the SWF format Flash ads, how to make these ads more orderly appearance, the site builders have used the flash advertising player, its form is also very rich, but the technology contains similar. Flash advertising players often need to replace the ads, so using external files to import to the advertising player is a feasible way. These external files include SWF, JPG and other formats of advertising files, organization of data XML files and CSS files used to format text, etc., so that changing ads, change the format of the text becomes very convenient. :
Prepare footage for the player
Create a table of contents, to save related files, for example, to play JPG images, first prepare several pictures, unified in a directory named "Mypic", named 1.jpg to N.jpg respectively.
Writing External Data files
1, write CSS file, a new TXT file, input the player text format content, such as font color. As shown below:
. message {
Color: #FFFFFF;
Font-family:arial,helvetica,sans-serif;
font-size:12px;
Font-weight:bold;
Save the file written above and change the file name to Styles.css.
2, write the XML file, create a new TXT file, enter the relevant data, as follows:
<?xml version= "1.0" encoding= "gb2312"?>
<info baseurl= "mypic/" delaytime= "8" >
<picname id= "0" name= "pic1.jpg" ><! [Cdata[<a href= "http://www.macromedia.com" target= "_blank" class= "message" > Information Technology Education phase 1th </a>]]></ Picname>
<picname id= "1" name= "pic2.jpg" ><! [Cdata[<a href= "http://www.macromedia.com" target= "_blank" class= "message" > Information Technology Education Phase 2nd </a>]]></ Picname>
<picname id= "2" name= "Pic3.jpg" ><! [Cdata[<a href= "http://www.macromedia.com" target= "_blank" class= "message" > 3rd photo </a>]]></ Picname>
<picname id= "3" name= "Pic4.jpg" ><! [Cdata[<a href= "http://www.macromedia.com" target= "_blank" class= "message" > 4th photo </a>]]></ Picname>
</info> is also saved as a myinfo.xml file.
writing the class library for the player The player has to load a variety of external files, so writing your own load class library is a good solution, starting with an abstract load class, defining properties, methods, and events, and other concrete load classes inheriting this abstract load class.
1. Abstract Loading class
Import Mx.utils.Delegate;
Import Mx.events.EventDispatcher;
Class Fc.load.AbstractLoad {
private Var dispatchevent:function;
public Var addeventlistener:function;
public Var removeeventlistener:function;
private Var Loadobject:object;
private Var Loadid:number;
function getbytesloaded () {
return loadobject.getbytesloaded ();
}
function Getbytestotal () {
return Loadobject.getbytestotal ();
}
Private Function checkprogress () {
var perloaded:number = Math.floor (getbytesloaded ()/getbytestotal () *100);
Dispatchevent ({type: "OnProgress", value:perloaded});
Endload (perloaded);
}
Private Function Startload () {
Eventdispatcher.initialize (this);
Loadid = SetInterval (Delegate.create (this, checkprogress), 30);
Dispatchevent ({type: "OnProgress", value:0});
}
Private Function Endload (perloaded) {
if (perloaded>=100) {
Dispatchevent ({type: "OnComplete", Value:loadobject});
Clearinterval (Loadid);
}
}
} 2, classes that load XML
Import Fc.load.AbstractLoad;
Import Mx.utils.Delegate;
Class Fc.load.Xml extends Abstractload {
private Var Loadobject:xml;
function Xml () {
Loadobject = new XML ();
Loadobject.ignorewhite = true;
System.usecodepage = true;
}
Public function Load (url:string) {
Loadobject.load (URL);
Startload ();
}
} 3, classes that load CSS
Import Fc.load.AbstractLoad;
Import Mx.utils.Delegate;
Class Fc.load.Css extends Abstractload {
private Var LoadObject:TextField.StyleSheet;
function Css () {
Loadobject = new Textfield.stylesheet ();
}
Public function Load (url:string) {
Loadobject.load (URL);
Startload ();
}
} 4, the class that loads the movie
Import Fc.load.AbstractLoad;
Class Fc.load.Movie extends Abstractload {
private Var Loadobject:movieclip;
function Movie (MC) {
Movie clips such as loading a movie
Loadobject = MC;
}
Public function Load (url:string) {
Loadobject.loadmovie (URL);
Startload ();
}
Public function unload () {
Loadobject.unloadmovie ();
}
5, writing loading class
Class Loading {
var _path:movieclip;
function Loading (p) {
_path = p;
}
function Create (value) {
_path.createtextfield ("Loading", _path.getnexthighestdepth (), 0, 0, 0, 0);
_path.loading.autosize = true;
_path.loading.text = "Loading" +value+ "%";
_path.loading._x = (200-_path.loading._width)/2;
_path.loading._y = (233-_path.loading._height)/2;
}
function Clear () {
_path.loading.removetextfield ();
}
}
make an ad player Layers are described below:
In the "background" layer, place the background of the advertisement player;
In the "label" layer, set the frame label to facilitate the jump frame;
In the "as" layer, place the appropriate loading, playback code, and so on, mainly contains four blank keyframes, frame 2nd is used to load the XML file and save the data in one object. frame 10th Load CSS file, the same information stored in an object, the 20th frame is mainly related to the playback code, such as loading advertising files, switching effects.
2, write the code to load the XML file:
Stop ();
Import fc.load.*
Import Mx.utils.Delegate;
var pic = new Object ();
object to save picture information
var xmlData = new Xml ();
Xmldata.load ("Myinfo.xml");
Xmldata.addeventlistener ("OnComplete", Delegate.create (this, loadcomplete));
Xmldata.addeventlistener ("OnProgress", Delegate.create (this, loadporgress));
function LoadComplete (obj) {
var readxml = Obj.value.firstChild;
Pic.path = Readxml.attributes.baseURL;
Picture path
Pic.time = Readxml.attributes.delayTime;
Picture delay Occurrence Time
Pic.list = [];
for (var i = 0; i<readxml.childnodes.length; i++) {
Pic.list[i] = new Object ();
Pic.list[i].id = readxml.childnodes[i].attributes.id;
Index Reads
Pic.list[i].name = Readxml.childnodes[i].attributes. Name;
Picture name Read
Pic.list[i].info = Readxml.childnodes[i].firstchild;
Text information
Trace (Pic.path+pic.list[i].name);
}
Delete XmlData;
gotoAndPlay ("CSS");
}
function loadporgress (obj) {
Trace ("Loading");
3, writing code to load CSS files
Stop ();
Import Fc.load.Css;
Import Mx.utils.Delegate;
var style = new Object ();
var cssdata:css = new Css ();
Cssdata.load ("Styles.css");
Cssdata.addeventlistener ("OnComplete", Delegate.create (this, loadcomplete));
Cssdata.addeventlistener ("OnProgress", Delegate.create (this, loadporgress));
function LoadComplete (obj) {
style = Obj.value;
gotoAndStop ("pic");
Delete Cssdata;
}
function loadporgress (obj) {
Loading
}
4, write load ads and other code Stop ();
Import Fc.load.Movie;
Import Mx.utils.Delegate;
Import mx.transitions.*;
Import mx.transitions.easing.*;
var Mytransitionmanager:transitionmanager;
var index:number = 0;
var time:number = 0;
var _timeid:number = 0;
var alpha = 10;
var showtext = true;
Init ();
Loading external JPG files
function init () {
var Picdata:movie = new Movie (This.createemptymovieclip ("PICMC", 1));
Picdata.load (Pic.path+pic.list[index].name);
Picdata.addeventlistener ("OnComplete", Delegate.create (this, loadcomplete));
Picdata.addeventlistener ("OnProgress", Delegate.create (this, loadporgress));
}
Load Completion function
function LoadComplete (obj) {
Picmc.onenterframe = function () {
if (this._width!= 0) {
Delete This.onenterframe;
Add a transition effect
var mytransitionmanager:transitionmanager = new Transitionmanager (PICMC);
Mytransitionmanager.starttransition ({type:pixeldissolve, Direction:Transition.IN, duration:0.5, easing: None.easenone, xsections:20, ysections:20});
var mylistener:object = new Object ();
Mylistener.alltransitionsindone = function (eventobj:object) {
SetText ();
};
Mytransitionmanager.addeventlistener ("Alltransitionsindone", MyListener);
}
};
}
function loadporgress (obj) {
}
Set up ad Description text
function SetText () {
This.createemptymovieclip ("TEXTMC", 2);
Textmc.createemptymovieclip ("MC", 2);
CREATEBG (TEXTMC.MC, 0, 233, 200, 20);
Textmc.createtextfield ("Showinfo", 1, 0, 0, 0, 0);
With (TEXTMC) {
Showinfo.wordwrap = false;
Showinfo.html = true;
Showinfo.autosize = true;
Showinfo.stylesheet = style;
Showinfo.htmltext = Pic.list[index].info;
var str = Showinfo.text;
Showinfo.text = str;
showinfo._x = (200-showinfo._width)/2;
showinfo._y = 233;
}
This.createtextfield ("ShowTime", 3, 0, 0, 0, 0);
Showtime.autosize = true;
Showtime.text = pic.time+ "S";
_timeid = SetInterval (This, "Delayfunc", 1000);
}
Text background
function CREATEBG (MC, SX, SY, W, h) {
Mc.beginfill (0x333333, 40);
Mc.linestyle (1);
Mc.moveto (SX, SY);
Mc.lineto (Sx+w, SY);
Mc.lineto (Sx+w, sy+h);
Mc.lineto (SX, SY+H);
Mc.lineto (SX, SY);
Mc.endfill ();
}
Time settings for each ad display
function Delayfunc () {
var temptime = Pic.time-time;
Showtime.text = temptime+ "S";
if (time>=pic.time) {
Clearinterval (_timeid);
Time = 0;
Disappear
var mytransitionmanager:transitionmanager = new Transitionmanager (PICMC);
Mytransitionmanager.starttransition ({type:pixeldissolve, Direction:Transition.OUT, duration:0.5, easing: None.easenone, xsections:20, ysections:20});
var mylistener:object = new Object ();
Mylistener.alltransitionsoutdone = function (eventobj:object) {
index++;
if (index>=pic.list.length) {
index = 0;
}
Init ();
};
Mytransitionmanager.addeventlistener ("Alltransitionsoutdone", MyListener);
}
time++;
This advertisement player uses the loaded class which has been written to facilitate the later loading operation. Use the transition classes provided by the system to easily produce a variety of transition effects. Therefore, the development of projects, if you can build their own class library, it will be more than half the effort.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.