Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
Old 09-21-2006, 09:30 AM   #1
Danielito
 
danielito540@hotmail.com's Avatar
 
Join Date: Sep 2006
Posts: 4
Send a message via MSN to danielito540@hotmail.com
Unhappy relative path to SWF in loadMovie() is relative to HTML page not the parent SWF

- Problem: a relative path URL defined in a loadMovie() script is relative to the HTML page containing the parent SWF, not the parent SWF of loaded SWF...

- This means that, if you want the SWFs to work in Flash Player as well as the in the HTML page (don't we all?!), the parent SWF must be in the same directory as the HTML page that contains it. The problem with this is that you can't embed that parent SWF from other HTML pages in different directories without breaking the relative links to the child SWFs.

Solutions??

- Just have one HTML page holding the parent SWF that loads all the children, but this is very limiting and in the job I'm on now - not possible

- You could have Absolute links to your child SWFs, but Best Practice of Actionscript advises against it.

- You could have multiple copies of the parent and child SWFs for each HTML page, even if they all look and work the same, with relative links to the child SWFs appropriate for each HTML page. You could re-save the one set of SWFs and make sure that the directory structure is the same for each HTML page so the loadMovie URLs don't have to be changed for each parent SWF - but that's just annoying. There must be a better way...

- One of the many posts I've read from people who've discovered this problem offered a bit of custom actionscript which can fix it by creating a 'relative absolute' path. It uses a function to generate a correct absolute path to each child SWF but it looks a bit complicated and I don't know if this is the way to go... The script is below with full description at http://www.flashzone.nl/archives/000234.php

public function getAbsoluteUrl(urlInput:String):String {
var strResult:String = "";
if(urlInput.indexOf("http://") > -1) //only convert when online
{
if(urlInput.indexOf(".swf") > -1) // only convert when an actual .swf file is used
{
strResult = urlInput.substring(0, urlInput.lastIndexOf("/")+1); // find absolut path minus filename of .swf
}
}
return strResult;
}

loadMovie(getAbsoluteUrl(_root._url) + "_assets/lib.swf");

FOR THE LOVE OF GOD WOULD SOME GENIUS PLEASE SHOW ME THE WAY!!!

I have a massive Flash site to do that will get bigger and deeper (in terms of loaded child SWFs) and I'm under the gun so I need to figure out what to do. I think I might just have the one HTML page but I'm not sure what the implications of this are yet...

Last edited by [email protected]; 09-21-2006 at 09:44 AM.
danielito540@hotmail.com is offline   Reply With Quote
Old 09-21-2006, 09:57 AM   #2
Cota
Super Moderator
 
Cota's Avatar
 
Join Date: Jul 2001
Location: NYC
Posts: 10,175
Default

Given the function, and in theory, it should work. Providing the relative path from the Parent SWF to the child. Have you tested this?
__________________
Color Wars™ | (kul′ər wôrs) n. - Open conflict between factions. www.theColorWars.com

cota - www.chadworkman.com | http://shavedplatypus.com
occupation: designer | flash developer | server-side developer (php, asp, mssql, mysql)
Cota is offline   Reply With Quote
Old 09-21-2006, 10:09 AM   #3
Danielito
 
danielito540@hotmail.com's Avatar
 
Join Date: Sep 2006
Posts: 4
Send a message via MSN to danielito540@hotmail.com
Default

Hi Cota,

Thanks for your response. Yeah I have tested it and it seems to be working but there's definitely more testing to be done... I've attached a zip of what I've got going on so far. Very basic. See what you think.

ps where do you upload a photo of yourself for actionscript.org? A man needs an identity!
Attached Files
File Type: zip folder.zip (18.4 KB, 844 views)
danielito540@hotmail.com is offline   Reply With Quote
Old 09-21-2006, 10:14 AM   #4
Cota
Super Moderator
 
Cota's Avatar
 
Join Date: Jul 2001
Location: NYC
Posts: 10,175
Default

In your userCP there is a section for "edit avatar"

Unfortunately, the machine I am doesnt have Flash installed, so I cant test it. Which was why I said, "in theory"..
__________________
Color Wars™ | (kul′ər wôrs) n. - Open conflict between factions. www.theColorWars.com

cota - www.chadworkman.com | http://shavedplatypus.com
occupation: designer | flash developer | server-side developer (php, asp, mssql, mysql)
Cota is offline   Reply With Quote
Old 06-07-2007, 06:55 PM   #5
noelb
Registered User
 
Join Date: Jun 2007
Posts: 2
Default

Probably too late a reply, but for anyone else who runs into the same problem, you can simply edit the embed tag for the flash and set a "base" path that's where you flash movies live.

Documentation here:
http://www.adobe.com/cfusion/knowled...fm?id=tn_12701
noelb is offline   Reply With Quote
Old 07-15-2008, 01:55 AM   #6
DesignByOnyx
Registered User
 
Join Date: Jul 2008
Posts: 2
Default A little late on this one too.

I just stumbled across this post, and thought it worthy to add my two cents as I struggled with this before. If you are using AS 2 (not sure about AS 3) you can use this._url in each of your child movies to find it's absolute location. Then compare that to _root._url to find the child swf's location relative to the _root swf. Hope that helps.
DesignByOnyx is offline   Reply With Quote
Old 07-15-2008, 02:31 AM   #7
atomic
Banned by AS.org Staff
 
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073
Default

BUt that would be an absolute path, not a relative one!
atomic is offline   Reply With Quote
Old 08-18-2008, 03:51 PM   #8
dragonlady
Registered User
 
Join Date: Aug 2008
Posts: 18
Default I'm having a similar problem as the original poster

Good morning everyone,

I too seem to be suffering from a relative path problem. Here's the situation: I have a website with the a .swf file, an html file with the .swf embedded, and a subdirectory of XML files. The swf is supposed to load the XML files and generate a map. Let's just say the directory structure looks like this (btw these are not the real URLs; I don't own the site and I would want to check with the site owner before making the links public):

Main page: http://mysite.org

Folder containing swf, html, and XML folder: http://mysite.org/mygame

Directory of XML files: http://mysite.org/mygame/XML Maps

Okay, so when I click the html file, the embedded swf file runs correctly, except when I click on a level, which is supposed to load the XML file. At that point the screen just loads up blank, no error messages or anything.

When I run the game on my local webserver (which is separate from the website that I'm having trouble with), the maps load and the window resizes correctly, so it doesn't seem to be an issue with the game itself.

I used noelb's solution of adding a "base" tag to the html file, but the problem persists. Again, I don't get an html error, just a blank screen. My next step is to try the ActionScript solution, but I'm really wondering why the extra html tag is not working. Does anybody have any possible insights as to where my problem might lie?

Thanks
dragonlady is offline   Reply With Quote
Old 08-18-2008, 03:58 PM   #9
atomic
Banned by AS.org Staff
 
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073
Default

What's the code to load the xml/maps?

Can you provide all files on their own, if not the site's address?
atomic is offline   Reply With Quote
Old 08-20-2008, 11:29 PM   #10
dragonlady
Registered User
 
Join Date: Aug 2008
Posts: 18
Default

Hi Atomic,

Sorry I didn't get back sooner; I was away for a couple of days. It turns out, that seemingly Flash doesn't like the URL. I tried a fresh Flash file, consisting only of:

var xmlLoader:URLLoader = new URLLoader();
var mapData:XML = new XML();


xmlLoader.addEventListener(Event.COMPLETE, loadMap);
xmlLoader.load(new URLRequest(fileName));

function loadMap(e:Event):void
{
trace("success);
}

When I put the URL to one of the XML map files, I get a 2032 error, an IOstream problem. I then tried it with an XML file stored on a tutorial at the Kirupa site, and it loaded that just fine. And I know the URL for my file exists, because I loaded it directly into my browser window with no problem.

I'm not really sure why that would be...

Here's the link for the file I'm trying to load:

http://dodgames.org/nuke/html/dotgam...ps/DftMap2.XML
dragonlady is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
passing radio button variables/values acperez ActionScript 1.0 (and below) 10 03-17-2006 12:20 PM
Relative path not working for loadMovie berlintintin ActionScript 1.0 (and below) 2 07-07-2005 06:52 PM
How to save a HTML page? apple HTML and JavaScript 1 01-31-2005 09:14 PM
Relative path breaks when using loadMovie - only on PC amateur6 ActionScript 1.0 (and below) 0 09-29-2004 05:28 PM
Load Movie ('swf file for which user clicked on an html page', 1) ? Touseef ActionScript 1.0 (and below) 3 07-24-2004 05:54 AM


All times are GMT. The time now is 09:17 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.