Okay, so basically i have a movieclip on the screen and a function which loads a picture into it when it enters the frame. But i also have a function which makes it rise and grow when it is rolled over and it worked fine until i added the loader because now it seems to have converted the whole clip to a loader or something because it tells me :
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Loader@32be3101 to flash.display.Sprite.
at Thisflashfile_fla::galleryInnerEndMc_26/…

this is the code:

gb1_mc.addEventListener(MouseEvent.MOU… mainLift); //Event listeners for the movieclip 
gb1_mc.addEventListener(MouseEvent.MOU… mainDrop); //for when it is rolled over 

function mainLift(event:MouseEvent):void { //function to make it rise on rollover
var thisOne:Sprite = Sprite(event.target)
thisOne.y -= 15
thisOne.x -= 10
thisOne.width += 20
}
function mainDrop(event:MouseEvent):void { //function to make it fall on rollout
var thisOne:Sprite = Sprite(event.target)
thisOne.y += 15
thisOne.x += 10
thisOne.width -= 20
} //all this works fine untill i added this:

gb1_mc.addEventListener(Event.ENTER_FR… addPicMain) //event listener for when it enters frame

function addPicMain(event:Event):void {
var picNum:Number = 1 //there are alot of them so i have a picture number variable
var imgRequest:URLRequest = new URLRequest("/galImgs/pic" + picNum + ".png"); //image location
var imgLoader:Loader = new Loader (); //creates loader
imgLoader.load(imgRequest); //loads it
event.target.addChild(imgLoader); //adds it to the movieclip*
}

*So i think this is where it screws up maybe the loader is going overtop of the movieclip causeing the other code not to work. Idk so if anyone could help it would be greatly appreciated if ur good with flash this is easy ten pts :) if i havnt done a good job explainign just ask
Thanks in advance


Sorry if thats bad i copied and pasted from last night i asked on yahoo answers but this place is obviously better so i ask here too :)

Recommended Answers

All 4 Replies

lol sorry about this i just realized i said something about points and obviously i cant give u points lol. But if there is a way u can tell me and i will :)

Member Avatar for rajarajan2017

Actually there is no logic to load one more picture in your code?, always it will utilize
picNum=1 while enters thru ENTER_FRAME event.

Finally you load the image into the movie clip and a loader inside, so every time it focus your loader and not your movie clip.
Check with the below code to load a picture and at the same time your over and out effect will work.

gb1_mc.addEventListener(MouseEvent.MOUSE_OVER, mainLift);
gb1_mc.addEventListener(MouseEvent.MOUSE_OUT,mainDrop);
gb1_mc.buttonMode=true;

function mainLift(event:MouseEvent):void {
var thisOne:Loader = Loader(event.target)
thisOne.y -= 15
thisOne.x -= 10
thisOne.width += 20
}
function mainDrop(event:MouseEvent):void {
var thisOne:Loader = Loader(event.target)
thisOne.y += 15
thisOne.x += 10
thisOne.width -= 20
}

addPicMain();

function addPicMain():void {
var picNum:Number = 1;
var imgRequest:URLRequest = new URLRequest("/galImgs/pic" + picNum + ".jpg");
var imgLoader:Loader = new Loader ();
imgLoader.load(imgRequest);
 gb1_mc.addChild(imgLoader);
}
Member Avatar for rajarajan2017

Hope this solve!

Hope this solve!

Worked fine, thank you a ton! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.