Ted Patrick > { Events & Community } > Adobe Systems


Problems with MovieClipDatatype

There are some fundamental problems with the MovieClipDataType (MCD). As MCD's are unlike any other datatype in flash (they are visual), they require special care and handling. Why is this so?

First MCD's are depth oriented but live in a name/path oriented player. Here are a few common errors that break down the path orientation of the player and force the developer to work around these issues.

=======================================================

ERROR 1 - Duplicate MCD's with same name/path on different depths. Lowest depth MCD takes precedence.

_level0.createEmptyMovieClip('ted', 0)
_level0.createEmptyMovieClip('ted', 1)
_level0.createEmptyMovieClip('ted', 2)
trace(ted + " " + ted.getDepth()) // output:"_level0.ted 0"
_level0.ted.swapDepths(23) // move depth 0 to 23
trace(ted + " " + ted.getDepth()) // output:"_level0.ted 1"

Rule = When adding MCD's, they should overwrite duplicate MCD's where the name is the same.

=======================================================

ERROR 2 - MCD's can conflict with the name/path of an object. Object takes precedence from MCD

_level0.createEmptyMovieClip('ted', 0)
_level0.ted = "Ted the String"
trace(ted) // output:"Ted the String"
delete ted
trace(ted) // output:"_level0.ted"

Rule = When adding MCD's, they should overwrite an Object with the same name. Objects added using the same name should overwrite MCD's.

=======================================================

ERROR 3 - Negative depths cannot be removed via removeMovieClip. Negative depths are auto assigned to MCD's that are added via the IDE. To remove them, you must first move them to a positive depth and execute removeMovieClip.

// add a MCD to stage in the IDE
// give it an instance name 'ted'
_level0.ted.removeMovieClip() // failed
_level0.ted.swapDepths(0) // move depth -16838 to 0
_level0.ted.removeMovieClip() // success!

Rule = All MCD's should be removable in all situations regardless of how they were added.

=======================================================

ERROR 4 - MovieClip methods require depth as an argument, yet there is no way to tell if a depth is occupies directly. Only by processing all movieClips can one know that you will not overwrite a MCD. Worse still you might overwrite another name/path with a completely different name/path.

Rule = MovieClip methods should be written without a depth argument and allow depth positioning in an argument neutral manner. (above, below, top, bottom)

=======================================================

ERROR 5 - Modification of MCD depth is difficult as it requires knowledge of the entire stack of MCD depths so that processing can occur. The provided swapDepth method is very low level, typically moving a MCD to top or bottom requires processing a majority of the MCD's with swapDepth.

Rule = Provide a method that positions MCD's without a depth argument in a relative manner to other MCD's. (above, below, top, bottom, swap)

=======================================================

Depth Management added to PowerSDK

To correct the shortcomings of the MCD, PowerSDK is adding 4 methods to MovieClip.prototype and replacing the error prone methods. This simplified developer interface provides all of the existing functionality but adds some flexibility. All this without having to worry about depth management every again.

MovieClip.prototype.attach(obj)
MovieClip.prototype.remove()
MovieClip.prototype.setDepth(type [, target])
MovieClip.prototype.__resolve // enforcement of Obj overwriting a MCD

replace MovieClip.prototype.attachMovie(name, id, depth, init)
replace MovieClip.prototype.createEmptyMovieClip(name, depth)
replace MovieClip.prototype.createTextField(name, depth)
replace MovieClip.prototype.duplicateMovieClip(name, depth, init)
remove MovieClip.prototype.getDepth()
replace MovieClip.prototype.removeMovieClip
replace MovieClip.prototype.swapDepths (target)

Old MovieClip methods are accessible within inside the new ones as follows:
MCD.attachMovie.old(name, id, depth, init)

// add emptyMCD - default depth is 'top'
MCD.attach({name:'myClip'})

// add MCD from library
MCD.attach({name:'myClip', id:'clip'})

// add emptyMCD and load an external movieclip inside
MCD.attach({name:'myClip', url:'http://swf_url'})

// add emptyMCD and initialize with data
MCD.attach({name:'myClip', init:{active:true}})

// add emptyMCD and initialize as a class
MCD.attach({name:'myClip', class:'myClipClass'})

// add emptyMCD specify depth
MCD.attach({name:'myClip', depth='top'})
MCD.attach({name:'myClip', depth='above', depthTarget = 'mc_ui'})
MCD.attach({name:'myClip', depth='below', depthTarget = 'mc_ui'})
MCD.attach({name:'myClip', depth='bottom'})

// add TextField
MCD.attach({name:'myClip', id:'textField'})

// remove a MCD
MCD.remove()

// set depth of an MCD
MCD.setDepth('top')
MCD.setDepth('bottom')
MCD.setDepth('above', 'mc_ui')
MCD.setDepth('below', 'mc_ui')
MCD.setDepth('swap', 'mc_ui')

The old methods remain accessible and use the same argument order to provide backward compatibility although, you will see trace errors on their use.

It takes about a day to feel comfortable with the player modifications, but it makes things more predictable and allows things that were once complex, to seem trivial.

After all, working on a higher level is what PowerSDK is all about!

I will post a URL when I am done testing the code, should be Wed. at the latest.

Cheers,

Ted ;)

0 Responses to “ Problems with MovieClipDatatype ”

Post a Comment



© 2008 Ted On Flash

Technorati Profile