-
[F8] changing code to function breaks it
Hi there, I'm trying to make this piece of code (that takes a jpg/gif turns it into bitmap data, and tiles it BEHIND everything else) into a function, so I can call it with different parameters (such as img url, description etc.).
This is the code inline, that works perfectly:
code:
initialLoad("loading wallpaper...");
img = "./images/bg.gif"
this.createEmptyMovieClip("tile_mc", this.getNextHighestDepth());
// trace(this.getNextHighestDepth());
loader = new MovieClipLoader()
loader.addListener(this)
loader.loadClip(img, _root.tile_mc)
function fillBG() {
this.beginBitmapFill(myBitmap);
this.moveTo(0,0);
this.lineTo(Stage.width,0);
this.lineTo(Stage.width,Stage.height);
this.lineTo(0,Stage.height);
this.lineTo(0,0);
this.endFill();
}
function onLoadInit() {
updateLoad("wallpaper loaded.");
myBitmap = new BitmapData(tile_mc._width, tile_mc._height,true,0x00FFFFFF)
myBitmap.draw(tile_mc)
tile_mc.removeMovieClip()
fillBG();
}
function onLoadError() {
tile_mc.removeMovieClip()
}
fillBG();
var stageL:Object = new Object();
stageL.onResize = function() { fillBG(); }
Stage.addListener(stageL);
Now this code is my attempt at modifying it to a function (just adding function x(), and closing {, then calling it)
code:
function loadTile() {
initialLoad("loading wallpaper..."); //changes text for preloader
img = "./images/bg.gif" //url to image
this.createEmptyMovieClip("tile_mc", this.getNextHighestDepth());
// trace(this.getNextHighestDepth());
loader = new MovieClipLoader()
loader.addListener(this)
loader.loadClip(img, _root.tile_mc)
function fillBG() {
this.beginBitmapFill(myBitmap); //this code tiles the bitmap
this.moveTo(0,0);
this.lineTo(Stage.width,0);
this.lineTo(Stage.width,Stage.height);
this.lineTo(0,Stage.height);
this.lineTo(0,0);
this.endFill();
}
function onLoadInit() {
updateLoad("wallpaper loaded.");
myBitmap = new BitmapData(tile_mc._width, tile_mc._height,true,0x00FFFFFF)
myBitmap.draw(tile_mc)
tile_mc.removeMovieClip()
fillBG();
}
function onLoadError() {
tile_mc.removeMovieClip()
}
fillBG();
var stageL:Object = new Object(); //this is a listener for when it resizes
stageL.onResize = function() { fillBG(); }
Stage.addListener(stageL);
}
loadTile();
Now the first code works perfectly, the second loads the bitmap ABOVE everything else, and doesn't tile.
I can't figure out what it is - any ideas?
Many thanks, look forward to some help - all help so far has been great! love you ALL!
-
try moving the functions that you have inside the main function to outside the outside the main function. I think that's where your problem is.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|