I have a myFile MC that loads a JPG using my_mc.loadClip(run_url, “myFile”);.then, I want to add some interaction, like:
myFile.onEnterFrame = function () {
trace (“bap”);
}
but it doesn’t work. Why is that? Does the loadClip code disables the MC’s main commands?
import mx.utils.Delegate; //helps to manage scope issues within callback functions
var streamingID:Number;
var fileLoaded:Boolean;
var dBar:MovieClip = this.Bars.dBar; //downloading bar
var progBarFactor = dBar._width/100; //pixel to percents
var space:Number = 50;
var proportion:Number;
var actualW:Number;
var actualH:Number;
var actualSize:Boolean = false;
function displayStreaming (theSource:Object) {
//check to see if track has finished downloading:
if (fileLoaded) {
clearInterval (streamingID);
dBar._x = dBar._width;
} else {
var percentLoaded:Number = Math.floor((theSource.getBytesLoaded()/ theSource.getBytesTotal())*100);
dBar._x = percentLoaded*progBarFactor;
}
}
function doneStreaming():Void {
fileLoaded = true;
}
MovieClip.prototype.screenFit = function(){
actualW = this._width;
actualH = this._height;
if ((this._width/this._height) > (Stage.width/Stage.height)) {
if (this._width > Stage.width - space*2) {
proportion = (this._height / this._width);
this._width = Stage.width - space*2;
this._height = this._width * proportion;
}
} else {
if (this._height > Stage.height - space) {
proportion = (this._width / this._height);
this._height = Stage.height - space*2;
this._width = this._height * proportion;
}
this._x = (Stage.width - this._width)/2;
this._y = (Stage.height - this._height)/2;
}
mask._x = this._x; mask._y = this._y;
mask._width = this._width;
mask._height = this._height;
delete onEnterFrame;
};
MovieClip.prototype.actualSize = function(){
this._height = actualH;
this._width = actualW;
this._x = (Stage.width - this._width)/2;
this._y = (Stage.height - this._height)/2;
if (this._width < Stage.width - space*2) {
mask._width = this._width;
mask._x = this._x;
} else {
mask._width = Stage.width - space*2;
mask._x = space;
}
if (this._width < Stage.width - space*2) {
mask._height = this._height;
mask._y = this._y;
} else {
mask._height = Stage.height - space*2;
mask._y = space;
}
}
myFile.onEnterFrame = function () {
trace ("bap");
if (actualSize == true && _xmouse > _parent.mask._x && _xmouse < _parent.mask._x + _parent.mask._width && _ymouse > _parent.mask._y && _ymouse < _parent.mask._y + _parent.mask._height) {
K = (_xmouse - _parent.mask._x) / (_parent.mask._x + _parent.mask._width - _xmouse);
targetX = _xmouse - K * this._width / (K+1);
K = (_ymouse - _parent.mask._y) / (_parent.mask._y + _parent.mask._height - _ymouse);
targetY = _ymouse - K * this._height / (K+1);
speed = 5;
this._x += (targetX - this._x) / speed;
this._y += (targetY - this._y) / speed;
}
}
fileLoaded = false;
my_mc = new MovieClipLoader();
my_mc.loadClip(run_url, "myFile");
my_mc.onLoadComplete = Delegate.create(this, doneStreaming);
streamingID = setInterval (displayStreaming, 100, myFile);
onEnterFrame = function(){
if (fileLoaded){
myFile.screenFit();
}
}
stop();