PDA

View Full Version : Calling functions from content in a scrollPane


alexerwin
07-20-2004, 09:14 PM
Hello,

I am trying to build something like the shopping cart on macromedia's website. I have determined that I would have to use a scrollpane to get vertical scroll. Here is the problem:

I am using a movie in my library as scrollpane.contentpath, the movie has functions in it so that it can create a new line base on parameters that I pass to it. When I attempt to trace the text of a label inside this content I get back the right data, but when I try to execute the function inside, it does absolutely nothing.

I have the following code:

var scrollarea = cartaccordian.cart.scroller.content;

I am attempting to do

scrollarea.myFunction(param1, param2, etc.)

but no luck :(

However when I do
trace(scrollarea.label.text); it will print
OR
scrollarea.label.text = "something"; it will display

I am new at Flash MX so could someone help me. I am guessing that this is probably a referencing issue but how do I reference functions embedded in the content of the scrollpane?


Alex Erwin

yorkeylady
07-20-2004, 10:52 PM
When you test the movie look under the debug menu, use the drop tab on the upper right corner and use find to search for the function name to see if the function is listed there. Is the function returning a value or are there any traces in it?
You could also try this to test if the function exists
if(myMovie.myFunction != undefined){
trace("my function exists");
}
I don't see anything wrong with your function call.

It looks like your not using strict coding with ActionScript 2.

alexerwin
07-21-2004, 07:27 PM
I am new to the AS 2 enviornment, what is strict coding?

I tried the following.

created a new movie on the stage
inserted a scrollpane instance in the new movie
named the instance "scroller"
created another movie clip with a label named core and a function named tester()
I exported the second clip

I then placed the following code into my first movie clip

trace(scroller.content.core.text);
scroller.content.tester();
if (scroller.content.tester() != undefined)
{
trace("I am here");
}

Alex

yorkeylady
07-22-2004, 12:45 AM
I added a ScrollPane component to the screen manually. It shows that the variables and function have been erased. I would make a movieclip that contains a masked movieclip and load into it instead.


loadListener = new Object();
loadListener.progress = function(eventObj) {
// eventObj.target is the component that generated the change event
var bytesLoaded = scrollPane.getBytesLoaded();
var bytesTotal = scrollPane.getBytesTotal();
var percentComplete = Math.floor(bytesLoaded/bytesTotal);
if (percentComplete<5) {
// loading just commences
} else if (percentComplete=50) {
//50% complete
trace(" 50% contents downloaded ");
}
};
loaded = new Object();
loaded.complete = function(eventObj) {
var width = eventObj.target._width+20;
var height = eventObj.target._height+20;
eventObj.target.setSize(width, height);
import myscript.as;
if (eventObj.target.content.myfun != undefined) {
eventObj.target.content.myfun("\nHi now we've got it.");
} else {
trace("myfun is undefined");
}
if (eventObj.target.content.aVar != undefined) {
trace(aVar+" variable shows.");
} else {
trace("aVar is undefined");
}

for(var prop in eventObj.target.content){
trace(prop+" "+eventObj.target.content[prop]);
}
};
scrollPane.addEventListener("complete", loaded);


--------------------------------output
myfun is undefined
aVar is undefined
setStyle [type Function]
notifyStyleChangeInChildren [type Function]
changeColorStyleInChildren [type Function]
changeTextStyleInChildren [type Function]
getStyle [type Function]
getStyleName [type Function]
_getTextFormat [type Function]
__getTextFormat [type Function]
destroyObject [type Function]
createEmptyObject [type Function]
createClassObject [type Function]
createObject [type Function]
createLabel [type Function]
getTopLevel undefined
buildDepthTable [type Function]
getDepthByFlag [type Function]
shuffleDepths [type Function]
findNextAvailableDepth [type Function]
setDepthBelow [type Function]
setDepthAbove [type Function]
setDepthTo [type Function]
createChildAtDepth [type Function]
createClassChildAtDepth [type Function]
useHandCursor false
tabChildren true
tabEnabled false
dispatchQueue [type Function]
dispatchEvent [type Function]
removeEventListener [type Function]
__origAddEventListener [type Function]
addEventListener [type Function]
size [type Function]
setSize [type Function]
move [type Function]
visible true
bottom NaN
right NaN
y 0
top 0
x 0
left 0
height 127
width 516
_complete true