Flash as Tutorial: Solving the Problem of relative paths during multi-layer Loading

Source: Internet
Author: User
The following prompt is displayed for creating a guide line webpage:This problem was discovered during multi-level loading today. the solution is pasted with the Problem description: The Path Structure is: root level: a.swf data (folder) data folder contains B .swf c.swf in B'sCodeWhen C. SWF runs B separately, it is normal. When a0000bis are used, the question "B" cannot begin c.swf. We need to move c.swfto and a.swf.

Today, this problem was discovered during multi-level loading, and the solution was posted.
Problem description:
The path structure is at the root level: B .swf c.swf IN THE a.swf data (folder) data folder
When C. SWF runs B separately in the code B, it is normal. When a0000bis are used, the question "B" cannot begin c.swf.
You must move c.swfto the same level as a.swf.

Cause:
All loaded SWF files use the directory of the outermost SWF as the root directory.
All SWF files loaded by webpages use the directory where the webpage is located as the root directory.

Solution:
Function compute file directory (){
VaR Directory Index = _ URL. lastindexof ("/");
VaR directory = _ URL. substring (0, Directory Index );
Var file name = _ URL. substring (Directory Index + 1 );
Return [directory, file name];
}
Trace (_ URL)
Trace (computing file directory ())

// ***** Focus. The preceding function separates the directory from the file name. Therefore, the returned value [0] is the directory [1] and the file name. This makes it easier to use.

Use the above function to analyze and obtain the absolute directory of the main loader. At this time, no matter the lower-level carrier or lower-level carrier, call this function again.
Obtain the absolute directory of the lower-level carrier.

In this way, we can get two absolute addresses and use the string analysis method (indexof) to find the same part. remove, and the rest is the required relative path. in this way, this path is appended during the loading. the file with N-level relationships can be normally loaded.

This tutorial is self-developed and only available for learning.

// Add the comparison method. It is relatively simple.
// ========= Calculate your own relative path ========
VaR Directory Index = file directory [0]. indexof (_ root. File directory [0])
VaR Relative Path = file directory [0]. substring (Directory Index + _ root. File directory [0]. Length + 1)
Trace ("Relative Path =" + relative path)

// ===== Trace environment === parsing successful.
Main file directory = file: // F |/create/
Sub-file directory = file: // F |/create/A/Data
Relative Path = Data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.