Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Works in Flash 6 but not 7 1

Status
Not open for further replies.

AndyH1

Programmer
Jan 11, 2004
350
GB
I have the following code in a piece of flash I wrote a while ago. It works perfectly well in Flash 5 and 6, but not 7. Can anyone advise me what I need to change to get it working in Flash 9. Iv'e looked for things like loadmovie and cannot see anything that is affected by the changes from Flash 6 to 7. It basically makes a series of movieclips grow when you move over it.


// Main code in root
// Defines Constants
descriptions = new Array();
links = new Array();
descriptions[0] = "Back to home page"
links[0] = "default.htm";
descriptions[1] = "Services we can provide"
links[1] = "services.htm";
descriptions[2] = "Portfolio of work for clients"
links[2] = "portfolio.htm";
descriptions[3] = "The technical skills we possess"
links[3] = "skills.htm";

// Define window functions.
// These will be added to the local window
// object to create the window.methods.
//
// set semaphores
winActive = new Object();
winActive = {state:false, owner:"no-one", fullWindow:false};
bootstrap = true;
//
function scaleMe (me, meActive) {
trace('scale me');
// if I am an active window, I need to grow...
if (meActive) {
var cs = _root[me]._xscale;
var cx = _root[me]._x;
var cy = _root[me]._y;
var scale = 24;
var damp = .72; //.72 will give bounce

xaccel += (_root[me]._x - _root[me]._x)*.2;
yaccel += (_root[me]._y - _root[me]._y)*.2;
saccel += (scale - _root[me]._xscale)*.2;

if (_root[me]._xscale +saccel <=2){
_root[me]._xscale = _root[me]._yscale = 2;
}else{
_root[me]._yscale += saccel;
_root[me]._xscale += saccel;
}

_root[me]._x += xaccel;
_root[me]._y += yaccel;


xaccel *= damp //damp
yaccel *= damp //damp
saccel *= damp //damp
_root.winActive.fullWindow = true
} else {
// ... otherwise I am not the active window and need to shrink.
if (_root[me]._xScale>16) {
_root[me]._xScale = _root[me]._xScale*0.90;
_root[me]._yScale = _root[me]._yscale*0.90;
// if I was previously the active window, I need to relinquish
// this title to let other windows in.
} else {
_root[me]._xScale =16;
_root[me]._yScale = 16;
}
// Because I am not Active I need to shrink
}
}

// Shows description in top associated with image
function showDescription(i) {
trace('show description');
_root.mcDescription.setText(_root.descriptions);
_root.mcDescription.gotoAndPlay("start");
}

// Gos to the website associated with image
function goToLink() {
getURL(links[_root.winActive.owner.charAt(4)]);
}

function setOwner(me) {
trace('setOwner');
var presentOwner = _root.winActive.owner;
// Note charAt below takes last character of name - will need to alter if
// have more than 10 items as only works with single digit
if (_root.winActive.owner <> me) showDescription(me.charAt(4));
_root.winActive.state = true;
_root.winActive.owner = me;
_root.bootstrap = false;
}

function cursorHit (me) {
trace('cursorHit');
// If there is a window currently hit and it is
// not me, I cannot be hit.
if (_root.winActive.state && ((_root.winActive.owner<>me) || _root.bootstrap)) {
return false;
} else {
hit = false;
// if I am currently under the cursor...
if ((_root[me]._x-_root[me]._width/2)<_root._xMouse) {
if ((_root[me]._x+_root[me]._width/2)>_root._xMouse) {
if ((_root[me]._y-_root[me]._height/2)<_root._yMouse) {
if ((_root[me]._y+_root[me]._height/2)>_root._yMouse) {
// ...set me to hit, and lock other windows out.
hit = true;
// this is where if cursor over
_root.setOwner(me);
}
}
}
}
// ... otherwise I was the last hit window, but I
// am not anymore, so I should release control...
if (!hit) {
_root.winActive.state = false;
_root.winActive.owner = "non";
}
}
return hit;
}
stop();

//Code in movie clip
onClipEvent (load) {
// Define my window object and methods.
window = new Object();
window.scale = _root.scaleMe;
window.cursorHit = _root.cursorHit;
// Initialize my home (new pseudo-property).
_parent.homeX = _parent._x;
_parent.homeY = _parent._y;
}
onClipEvent (enterFrame) {
window.scale(_parent._name, window.cursorHit(_parent._name));
}
onClipEvent(mouseUp) {
_root.gotoLink();
}

Any help would be appreciated
Thanks
Andy
 
Few things you need to be aware:
[ul]
[li][tt]_xScale[/tt] is not the same as [tt]_xscale[/tt][/li]
[li][tt]_xscale/_yscale[/tt] is 100 based, not 1 based[/li]
[li][tt]_xMouse[/tt] is not the same as [tt]_xmouse[/tt][/li]
[li]You should use [tt]!=[/tt] instead of [tt]<>[/tt][/li]
[li]You're confusing [tt]_parent[/tt] for [tt]this[/tt][/li]
[/ul]
But this whole code can be written in may be 10 lines, I would re-write from scratch if I were you.


Kenneth Kawamoto
 
Thanks - tried your suggestions and my code is now below, seems to help but still getting problems - again runs fine in 6 but not 7. Any other ideas?
Thanks
Andy

Main code
// Defines Constants
descriptions = new Array();
links = new Array();
i = 0;
descriptions[0] = "Back to home page"
links[0] = "default.htm";
descriptions[1] = "Services we can provide"
links[1] = "services.htm";
descriptions[2] = "Portfolio of work for clients"
links[2] = "portfolio.htm";
descriptions[3] = "The technical skills we possess"
links[3] = "skills.htm";
descriptions[4] = "Testimonials from our clients"
links[4] = "testimonials.htm";
descriptions[5] = "About Serco - its history and skills?"
links[5] = "about.htm";
descriptions[6] = "Further information and documents"
links[6] = "documents.htm";
descriptions[7] = "How to Contact Us"
links[7] = "contactus.htm";
// Define window functions.
// These will be added to the local window
// object to create the window.methods.
//
// set semaphores
winActive = new Object();
winActive = {state:false, owner:"no-one", fullWindow:false};
bootstrap = true;
//
function scaleMe (me, meActive) {
// if I am an active window, I need to grow...
if (meActive) {
var cs = _root[me]._xscale;
var cx = _root[me]._x;
var cy = _root[me]._y;
var scale = 24;
var damp = .72; //.72 will give bounce

xaccel += (_root[me]._x - _root[me]._x)*.2;
yaccel += (_root[me]._y - _root[me]._y)*.2;
saccel += (scale - _root[me]._xscale)*.2;

if (_root[me]._xscale + saccel <=2){
_root[me]._xscale = _root[me]._yscale = 2;
}else{
_root[me]._yscale += saccel;
_root[me]._xscale += saccel;
}

_root[me]._x += xaccel;
_root[me]._y += yaccel;


xaccel *= damp //damp
yaccel *= damp //damp
saccel *= damp //damp
_root.winActive.fullWindow = true
} else {
// ... otherwise I am not the active window and need to shrink.
if (_root[me]._xscale>16) {
_root[me]._xscale = _root[me]._xscale * 0.90;
_root[me]._yscale = _root[me]._yscale * 0.90;
// if I was previously the active window, I need to relinquish
// this title to let other windows in.
} else {
_root[me]._xscale =16;
_root[me]._yscale = 16;
}
// Because I am not Active I need to shrink
}
}

// Shows description in top associated with image
function showDescription(i) {
_root.mcDescription.setText(_root.descriptions);
_root.mcDescription.gotoAndPlay("start");
}

// Gos to the website associated with image
function goToLink() {
getURL(links[_root.winActive.owner.charAt(4)]);
}

function setOwner(me) {
var presentOwner = _root.winActive.owner;
// Note charAt below takes last character of name - will need to alter if
// have more than 10 items as only works with single digit
if (_root.winActive.owner != me) showDescription(me.charAt(4));
_root.winActive.state = true;
_root.winActive.owner = me;
_root.bootstrap = false;
}

function cursorHit (me) {
// If there is a window currently hit and it is
// not me, I cannot be hit.
if (_root.winActive.state && ((_root.winActive.owner <> me) || _root.bootstrap)) {
return false;
} else {
hit = false;
// if I am currently under the cursor...
if ((_root[me]._x-_(root[me]._width/2)<_root._xmouse)) {
if ((_root[me]._x + (_root[me]._width/2)) > _root._xmouse) {
if ((_root[me]._y - (_root[me]._height/2))<_root._ymouse) {
if ((_root[me]._y + (_root[me]._height/2))>_root._ymouse) {
// ...set me to hit, and lock other windows out.
hit = true;
// this is where if cursor over
_root.setOwner(me);
}
}
}
}
// ... otherwise I was the last hit window, but I
// am not anymore, so I should release control...
if (!hit) {
_root.winActive.state = false;
_root.winActive.owner = "non";
}
}
return hit;
}
stop();

In movieclip
onClipEvent (load) {
// Define my window object and methods.
window = new Object();
window.scale = _root.scaleMe;
window.cursorHit = _root.cursorHit;
// Initialize my home (new pseudo-property).
_parent.homeX = _parent._x;
_parent.homeY = _parent._y;

}
onClipEvent (enterFrame) {
window.scale(_parent._name, window.cursorHit(_parent._name));
}
onClipEvent(mouseUp) {
_root.gotoLink();
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top