0

I'm trying to get my SWF loader to work with an array so I can call my swf files via one code, using buttons. This is the problem I am getting:

Scene 1, Layer 'actions', Frame 2, Line 68 1067: Implicit coercion of a value of type Array to an unrelated type String.

I am not too good with arrays, or strings, or coding tbh, i'm not too sure what the problem is, I understand it, my array and my string don't work together,basically, but I don't know how to fix it, if it can be fixed/work with the code I am using.

just some help and being pointed in the right direction would be a treat

var swfList:Array = ["imagegallery.swf", "videoplayer.swf"];
var SWFLoader = new Loader;
var SWFRequest = new URLRequest (swfList) ;
SWFLoader.load (SWFRequest) ;


function loadSWF(file:String, container:MovieClip=null):void
{
if(container == null) container = MovieClip(root);


if(SWFLoader != null)
{
    if(SWFLoader.parent) SWFLoader.parent.removeChild(SWFLoader);
}

addChild (SWFLoader);
}

vidPlayer_btn.addEventListener (MouseEvent.CLICK, goVidPlayer);

function goVidPlayer (e:MouseEvent):void
{
loadSWF("videoplayer.swf");
}
imageGallery_btn.addEventListener(MouseEvent.CLICK, goImageGallery);
function goImageGallery(e:MouseEvent):void
{
loadSWF("imagegallery.swf");
}
2
  • What's the point of having an array if you're just gonna access the strings individually? Commented Feb 5, 2013 at 17:14
  • there probably isn't, i was just trying some different stuff out, if theres a way to use the code without the string that would be helpful. it was more to try and have one code for both buttons instead of two separate codes. Commented Feb 5, 2013 at 17:28

2 Answers 2

3

To access items within an array use this format:

var SWFRequest = new URLRequest(swfList[i]);

Where i is the position in array (starting at zero). For instance:

var SWFRequest = new URLRequest(swfList[0]);

gives the same result as:

var SWFRequest = new URLRequest("imagegallery.swf");
Sign up to request clarification or add additional context in comments.

Comments

0

Did away with the array but still "have one code for both buttons instead of two separate codes".

// Looks unnecessary
// var swfList:Array = ["imagegallery.swf", "videoplayer.swf"];

// Transfer inside loadSWF()
// var SWFRequest = new URLRequest (swfList); // needs a url String parameter
// SWFLoader.load (SWFRequest);

var SWFLoader = new Loader();  // Don't forget the parenthesis

vidPlayer_btn.addEventListener (MouseEvent.CLICK, goVidPlayer);
imageGallery_btn.addEventListener(MouseEvent.CLICK, goImageGallery);

function goVidPlayer (e:MouseEvent):void
{
    loadSWF("videoplayer.swf");
}

function goImageGallery(e:MouseEvent):void
{
    loadSWF("imagegallery.swf");
}

function loadSWF(file:String, container:MovieClip=null):void
{
    // What for?
    // if(container == null) container = MovieClip(root);

    if(SWFLoader != null)
        if(SWFLoader.parent)
            SWFLoader.parent.removeChild(SWFLoader);

    var SWFRequest = new URLRequest (file) ;
    SWFLoader.load (SWFRequest);
    addChild (SWFLoader);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.