PDA

View Full Version : how to use depths with dynamic clips


cangeceiro
12-18-2007, 02:46 PM
Im currently working on building a revolving image ticker type system with flash. but im having a few issues.

the issue im stumped on is depth swapping in flash. I have a for loop that dynamically creates copies of a movie clip i have in my library based on data pulled from a drupal/amfphp services setup. The clip has 2 text fields, the mx.loader component, and a button. . This being the first time i have worked with depths, im really not sure where to even begin to get this to work right. ideally i want to mouse over one of the instances of the clip and it come to the front.

this is my first time working with remoting and depths, so i could be going about this all wrong.

here is my code.

first frame

import mx.remoting.*;
import mx.rpc.*;
import mx.utils.Delegate;
import mx.remoting.debug.NetDebug;

var gatewayUrl:String = siteRoot + "/services/amfphp";
var imagePath:String = "files/imagecache/flash_image/";
var view:Service = new Service(gatewayUrl, null, "views", null, null);

infoTxt.text = "Loading....";

NetDebug.initialize();

getView('flash_feed','onResultSuccess',['title','path','teaser','field_flash_rotation_imag e']);

function onResultSuccess(re:ResultEvent){
var oTicker:Object = re.result;
var xpadding:Number = 400/oTicker.length;
var z:Number = 0;
var countDown:Number = oTicker.length;
var counter = countDown;

for (i = 0; i < oTicker.length; i++) {
if (i == 0) {
alphaVal = 100;
} else {
alphaVal = 50;
}

trace("Path:" + oTicker[i].path);
trace("Counter:" + counter);

imageClip = this.attachMovie('imageClip','image' + i, counter, {
_x:0,
_y:0,
_alpha:alphaVal,
xpadding:z,
titleText:oTicker[i].title,
teaserText:oTicker[i].teaser,
path:oTicker[i].path,
imageHolder:siteRoot + imagePath + oTicker[i].field_flash_rotation_image[0].filepath
});
imageClip.onEnterFrame = updateClip;
z=z+xpadding;
counter = countDown-1;
}
}

function getView (viewName:String, handler:String, fields:Array, arg:Array) {
var pc:PendingCall = view.getView (viewName, fields, arg);
pc.responder = new RelayResponder (this, handler, "handleRemotingError");
}

function handleRemotingError (fault:FaultEvent):Void {
NetDebug.trace ({level:"None", message:"Error: " + fault.fault.faultstring});
}

function updateClip() {
this.titleTxt.text = this.titleText;
this.teaserTxt.text = this.teaserText;
this.imageLoader._x = this.xpadding;
this.gotoBtn._x = this.xpadding;
this.imageLoader.contentPath = this.imageHolder;
this.infoLoaded = imageLoader.getBytesLoaded();
this.infoTotal = imageLoader.getBytesTotal();
this.percentage = Math.floor(this.infoLoaded/this.infoTotal*100);
infoTxt.text = percentage+"%";
if (percentage>=100) {
delete this.onEnterFrame;
//infoTxt._visible = false;
}
}




button in image_clip from library


on(release) {
getURL(path);
}

on(rollOver) {
trace("Rollover start:" + _parent.getDepth());
titleTxt._visible = true;
teaserTxt._visible = true;
trace("Rollover after:" + _parent.getDepth());
}

on(rollOut) {
trace("Rollout start:" + _parent.getDepth());
titleTxt._visible = false;
teaserTxt._visible = false;
trace("Rollout after:" + _parent.getDepth());
}

xxneon
12-18-2007, 03:26 PM
try this in your rollover code..

this.swapDepths(10000);

that will most-likely push that specific clip to the front on rollover..

cangeceiro
12-18-2007, 03:38 PM
try this in your rollover code..

this.swapDepths(10000);

that will most-likely push that specific clip to the front on rollover..

nope, this didnt work. the button that has the roll over code is apart of the clip that is being dynamically generated. im not sure if this makes a difference. also worth noting....I tried _parent.swapDepths(10000); as well and the depth for each object originally starts at -16384 and after rolling over the first time it goes to 10000, but all instances stay at that even with roll out code that should be reverting it.

xxneon
12-18-2007, 03:46 PM
well no two objects can have the same depth .. so you need to make sure your targeting the right movieclip so your swaping the depths right..

if your getting a negative depth .. then your targeting something that was added manually..

your depths for the attached movieclips should be positive.. make if you sent a compressed fla we can see what your doing ..

also when you attach code to button instances like you are .. the buttons scope is its parent .. so if you do a trace(this); inside the on(rollover) it should return the name of the parent movieclip that it resides in..

cangeceiro
12-18-2007, 03:55 PM
well no two objects can have the same depth .. so you need to make sure your targeting the right movieclip so your swaping the depths right..

if your getting a negative depth .. then your targeting something that was added manually..

your depths for the attached movieclips should be positive.. make if you sent a compressed fla we can see what your doing ..

also when you attach code to button instances like you are .. the buttons scope is its parent .. so if you do a trace(this); inside the on(rollover) it should return the name of the parent movieclip that it resides in..

AH HA!!!! your explanation of the parent/child relation between clips is what i needed. i had a line on the rollOut that was setting the depth wrong, and i was trying to access the wrong element.